2011-05-10 44 views
2

我正在創建一個存儲過程,我不能爲我的生活弄清楚它有什麼問題。我需要另一套眼睛,這裏沒有人能幫助我。這是我的代碼:爲什麼我找不到多部分標識符?

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] 

錯誤消息:

(11行(一個或多個)受影響) 消息4104,級別16,狀態1,過程JeffApprovedPrograms,第26行 多部分標識符「AP .SchoolID「無法綁定。

我由於某種原因沒有看到問題。我將不勝感激任何幫助。

+1

爲什麼沒有'JOIN'條件,你的'#Schoolist'表?你也有一些語法錯誤,比如單個'JOIN'的多個'ON'語句...... – JNK 2011-05-10 15:02:14

+0

@JNK - 在AP上有一個連接條件[SchoolID] = SL。[SchoolID]'但它是在導致此錯誤消息的錯誤位置。 – 2011-05-10 15:12:32

+0

我不知道他們爲什麼按照他們的方式編碼,我正在努力清理它。 – Tharnid 2011-05-10 15:16:34

回答

2
JOIN #SchoolList SL 

JOIN[inters].[inters_tblDOECode] DE 
ON AP.[SchoolID] = SL.[SchoolID] 
-- JOIN [inters].[inters_tblJobCode] JC 
ON AP.[CipCode] = DE.[DOECode] 

應該

JOIN #SchoolList SL 
    ON AP.[SchoolID] = SL.[SchoolID]  
JOIN [inters].[inters_tblDOECode] DE 
    ON AP.[CipCode] = DE.[DOECode] 
+0

非常好...謝謝!!! – Tharnid 2011-05-10 15:23:27

+0

其實它是:ON DE。[CipCode] = DE。[DOECode] ....我在比較蘋果和橘子:) – Tharnid 2011-05-12 10:32:37