2012-10-11 41 views
0

我已經負責基於OrdinalPosition創建一個sql腳本,據我所知我的代碼應該可以工作,但顯然最後一個「ViewData」附近有一個「不正確的語法」錯誤.SONumber「,我無法解決和無法識別。有人可以看一看,看看我的大腦是不是正在處理的東西?Pivot中的語法不正確

FROM tblReps RIGHT OUTER JOIN tblServiceOrders RIGHT OUTER JOIN  dbo.tblCustomFieldDefinitions LEFT OUTER JOIN 
        (SELECT SONumber, [1] AS [ShippingCompany], [2] AS [Consignment_Number] 
        FROM  (SELECT  tvw_CustomSOFieldData.SONumber, tvw_CustomSOFieldData.CustomFieldValue, tvw_CustomSOFieldData.OrdinalPosition 
           FROM tvw_CustomSOFieldData) 
           PivotData PIVOT(max(CustomFieldValue) FOR OrdinalPosition IN ([1], [2])) AS CustomFieldsPivot) 
           AS ViewData ON tblServiceOrders.SONumber = ViewData.SONumber 

回答

0

那麼看起來你缺少幾種與你的語法相關的東西。您在幾個JOIN s上缺少ON語法:

FROM tblReps 
RIGHT OUTER JOIN tblServiceOrders 
    ON -- missing JOIN 
RIGHT OUTER JOIN dbo.tblCustomFieldDefinitions 
    ON -- missing JOIN 
LEFT OUTER JOIN 
(
    SELECT SONumber, 
    [1] AS [ShippingCompany], 
    [2] AS [Consignment_Number] 
    FROM   
    (
    SELECT tvw_CustomSOFieldData.SONumber, 
     tvw_CustomSOFieldData.CustomFieldValue, 
     tvw_CustomSOFieldData.OrdinalPosition 
    FROM tvw_CustomSOFieldData 
) PivotData 
    PIVOT 
    (
    max(CustomFieldValue) 
    FOR OrdinalPosition IN ([1], [2]) 
) CustomFieldsPivot 
) ViewData 
    ON tblServiceOrders.SONumber = ViewData.SONumber 
+0

但當然!謝謝你,先生,這樣一個簡單而愚蠢的錯誤 – LordJubbles

+0

也許語法鼓勵它。 –