Why am I getting a multi-part identifier could not be found?
I am creating a stored procedure and I can't for the life of me figure out what is wrong with it. I need another set of eyes on it a开发者_StackOverflow社区nd no one here can help me. Here is my code:
SELECT AP.[TermID]
,TE.TermName
,AP.[SchoolID]
, SchoolCode, SchoolName
,CASE WHEN [SA_Level] = 'A' THEN 'Adult' ELSE 'Secondary' END AS StudentType
,DE.[DOECode]
,DE.[DOEName]
,[LabMarWage]
FROM [inters].[inters_tblApprovedProgramsTest] AP
JOIN #SchoolList SL
JOIN[inters].[inters_tblDOECode] DE
ON AP.[SchoolID] = SL.[SchoolID]
-- JOIN [inters].[inters_tblJobCode] JC
ON AP.[CipCode] = DE.[DOECode]
LEFT JOIN [inters].[inters_tblLabMarWage] LM
ON DE.[LabMarWageID] = LM.[LabMarWageID]
JOIN [inters].[inters_tblTerm] TE
ON AP.[TermID] = TE.[TermID]
WHERE [IsActive] = 1
AND TE.TermName = @TermName
AND [SA_Level] = 'S'
AND ( @CipFilter = 0
OR ( @CipFilter = 1 AND DE.[LabMarWageID] IS NOT NULL))
ORDER BY TermName
,SchoolName
,[SA_Level]
,[DOECode]
,[CreditHours]
Error Message:
(11 row(s) affected) Msg 4104, Level 16, State 1, Procedure JeffApprovedPrograms, Line 26 The multi-part identifier "AP.SchoolID" could not be bound.
I am not seeing the problem for some reason. I would appreciate any help I could get.
JOIN #SchoolList SL
JOIN[inters].[inters_tblDOECode] DE
ON AP.[SchoolID] = SL.[SchoolID]
-- JOIN [inters].[inters_tblJobCode] JC
ON AP.[CipCode] = DE.[DOECode]
Should be
JOIN #SchoolList SL
ON AP.[SchoolID] = SL.[SchoolID]
JOIN [inters].[inters_tblDOECode] DE
ON AP.[CipCode] = DE.[DOECode]
精彩评论