I am getting this on the first line what am I doing wrong?
The multi-part identifier "t.clms" could not be bound.
SELECT n.doc, t.clms, Isnull(pendfoover1, 0) AS PendFOover1 , Isnull(pendfoover2, 0) AS PendFOover2, Isnull(pendfoover3, 0) AS PendFOover3
into #temppd
FROM natdocfile n
LEFT JOIN
(SELECT t.fo, t.clms, Isnull(COUNT(t.clms), 0) AS PendFOover1
FROM t16pendall t
WHERE(mft_POSN1_CD in('b','d') or (MFT_POSN1_CD='a' and aged_alien_rsw='y'))
and t.clms not in(select clms from t16pendmvt)
and (Datediff(DAY, t.flg_cdt, Getdate()) > 300)
group by t.fo, t.clms)d
on n.doc=d.fo
LEFT JOIN
(SELECT t.fo, t.clms, Isnull(COUNT(t.clms), 0) AS PendFOover2
FROM t16pendmvt m JOIN t16pendall t ON m.clms= t.clms
WHERE( mvt_typ = 'R' ) AND not (mvt_loc LIKE 'R%'
or mvt_loc LIKE 'S%'
OR mvt_loc LIKE 'V%' )
and (Datediff(DAY, t.flg_cdt, Getdate()) > 300 )
GROUP BY t.fo, t.clms)f
on n.doc=f.fo
LEFT JOIN
(SELECT t.fo, t.clms, Isnull(COUNT(t.clms), 0) AS PendFOover3
FROM t16pendmvt m JOIN t16pendall t ON m.clms= t.clms
WHERE mvt_typ = 't'
and (Datediff(DAY, t.flg_cdt, Getdate()) > 300 )
GROUP BY t.fo, t.clms)g
on n.doc = g.fo
The multi-part identifier "t.clms" could not be bound.
SELECT n.doc, t.clms, Isnull(pendfoover1, 0) AS PendFOover1 , Isnull(pendfoover2, 0) AS PendFOover2, Isnull(pendfoover3, 0) AS PendFOover3
into #temppd
FROM natdocfile n
LEFT JOIN
(SELECT t.fo, t.clms, Isnull(COUNT(t.clms), 0) AS PendFOover1
FROM t16pendall t
WHERE(mft_POSN1_CD in('b','d') or (MFT_POSN1_CD='a' and aged_alien_rsw='y'))
and t.clms not in(select clms from t16pendmvt)
and (Datediff(DAY, t.flg_cdt, Getdate()) > 300)
group by t.fo, t.clms)d
on n.doc=d.fo
LEFT JOIN
(SELECT t.fo, t.clms, Isnull(COUNT(t.clms), 0) AS PendFOover2
FROM t16pendmvt m JOIN t16pendall t ON m.clms= t.clms
WHERE( mvt_typ = 'R' ) AND not (mvt_loc LIKE 'R%'
or mvt_loc LIKE 'S%'
OR mvt_loc LIKE 'V%' )
and (Datediff(DAY, t.flg_cdt, Getdate()) > 300 )
GROUP BY t.fo, t.clms)f
on n.doc=f.fo
LEFT JOIN
(SELECT t.fo, t.clms, Isnull(COUNT(t.clms), 0) AS PendFOover3
FROM t16pendmvt m JOIN t16pendall t ON m.clms= t.clms
WHERE mvt_typ = 't'
and (Datediff(DAY, t.flg_cdt, Getdate()) > 300 )
GROUP BY t.fo, t.clms)g
on n.doc = g.fo