I keep getting these errors:
Msg 4104, Level 16, State 1, Line 80 The multi-part identifier "t.flngKey" could not be bound. Msg 4104, Level 16, State 1, Line 81 The multi-part identifier "t.flngKey" could not be bound. Msg 4104, Level 16, State 1, Line 82 The multi-part identifier "t.flngAccountKey" could not be bound.
SELECT t.flngKey AS flngTaskKey,
t.fstrAccountType,
t.fstrTaskSource,
CASE t.fstrCategory
WHEN '' THEN ''
ELSE t.fstrTaskSource + '_CAT_' + t.fstrCategory
END AS fstrCategory,
CASE
WHEN t.fstrType = '' THEN ''
WHEN wd.fstrWorkType = 'SUSIN1'
AND wd.fstrOwner = ' '
AND wd.flngworkkey = wr.flngworkkey
AND wr.fstrAccountType <> '007'
AND wr.fblnOpen = 1
AND EXISTS
(SELECT 1
FROM tblIndicator id
WHERE id.fstrIndicator = 'EIWTCH'
AND id.flngVer = 0
--AND fdtmCease > @pdtmRunDate
AND id.flngAccountKey = wd.flngAccountKey)
THEN 'Suspended for Audit Indicator - EIC Watch For'
ELSE t.fstrTaskSource + '_TYP_' + t.fstrType
END AS fstrType,
CASE t.fstrStage
WHEN '' THEN ''
ELSE t.fstrTaskSource + '_STG_' + t.fstrStage
END AS fstrStage,
ISNULL(t.fdtmFilingPeriod, '31-Dec-9999') AS fdtmFilingPeriod,
t.flngKey,
t.flngAccountKey,
t.flngCustomerKey,
'' AS fstrReturnStatus,
t.fdtmCreated,
t2.fdtmOldestCreated,
ISNULL(l.fstrCode,
ISNULL(lr.fstrPOCode, '')) AS fstrPOCode,
1 AS flngCount,
CASE t.fstrAssignedTo
WHEN '' THEN 'Unassigned'
ELSE 'Assigned'
END AS fstrAssigned,
(SELECT t3.fstrOwner
FROM t3
WHERE t3.fstrUser = t.fstrAssignedTo) AS fstrOwner,
(SELECT t3.fstrSBU
FROM t3
WHERE t3.fstrUser = t.fstrAssignedTo) AS fstrUnit
FROM tblTaskOpen t with (nolock) LEFT OUTER JOIN WIS_GTIMG.DBO.TBLImgCaseToImage ci with (NOLOCK)
ON t.flngkey = ci.flngCaseKey
AND t.fstrTaskSource = 'CASE' LEFT OUTER JOIN WIS_GTIMG.DBO.TBLImgIndex i with (NOLOCK)
ON ci.flngimagekey = i.flngimagekey
AND i.fstrindextype = 'DLN'
AND i.fblnValid = 1 LEFT OUTER JOIN WIS_GTEXT.DBO.tblWI_LevyResponse l with (NOLOCK)
ON i.fstrIndexId = l.fstrDLN
AND i.fstrindextype = 'DLN'
AND i.fblnValid = 1 LEFT OUTER JOIN WIS_GTEXT.DBO.TBLWI_letterResponses lr with (NOLOCK)
ON i.fstrindexid = lr.fstrDLN
AND i.fstrindextype = 'DLN'
AND i.fblnValid = 1 ,
t2
LEFT OUTER JOIN tblWorkToReturn wr
ON t.flngKey=wr.flngWorkKey LEFT OUTER JOIN tblWorkDetail wd **-- THE ERRORS REFER TO THESE LINES**
ON t.flngKey=wd.flngWorkKey LEFT OUTER JOIN tblIndicator id
ON (t.flngAccountKey=id.flngAccountKey AND id.fstrIndicator='EIWTCH')
WHERE t.fstrCategory <> 'ABC'
AND t.fstrCategory = t2.fstrCategory
AND t.fstrType = t2.fstrType
AND NOT EXISTS (SELECT 'xyz'
FROM tblaudit a
WHERE a.flngAuditkey = t.flngKey
AND a.fblnPosted = 1
AND t.fstrTaskSource = 'aud')
Thanks guys for all the help!
--EDIT: FOUND A SOLUTION--
I used this to help The multi-part identifier could not be bound
I edited the code to look like this
FROM tblTaskOpen t with (nolock) LEFT OUTER JOIN WIS_GTIMG.DBO.TBLImgCaseToImage ci with (NOLOCK)
ON t.flngkey = ci.flngCaseKey
AND t.fstrTaskSource = 'CASE' LEFT OUTER JOIN WIS_GTIMG.DBO.TBLImgIndex i with (NOLOCK)
ON ci.flngimagekey = i.flngimagekey
AND i.fstrindextype = 'DLN'
AND i.fblnValid = 1 LEFT OUTER JOIN WIS_GTEXT.DBO.tblWI_LevyResponse l with (NOLOCK)
ON i.fstrIndexId = l.fstrDLN
AND i.fstrindextype = 'DLN'
AND i.fblnValid = 1 LEFT OUTER JOIN WIS_GTEXT.DBO.TBLWI_letterResponses lr with (NOLOCK)
ON i.fstrindexid = lr.fstrDLN
AND i.fstrindextype = 'DLN'
AND i.fblnValid = 1 LEFT OUTER JOIN tblWorkToReturn wr
ON t.flngKey=wr.flngWorkKey LEFT OUTER JOIN tblWorkDetail wd
ON t.flngKey=wd.flngWorkKey LEFT OUTER JOIN tblIndicator id
ON (t.flngAccountKey=id.flngAccountKey AND id.fstrIndicator='EIWTCH'),
t2
this got it to work because it left joins against the t table, instead of the t2 table which was listed after. even though you can specify what to join on, these won't necessarily determine which table it is joined on. in this case, since all the subsequent lines of code after t is declared in FROM are joins, they all reference the same table, t. i found that the commas are helpful in determining which table it is joining. notice there are no commas until right before declaring t2.