0

我的任务是创建一个基于 OrdinalPosition 的 sql 脚本,据我所知我的代码应该可以工作,但是在最后一个“ViewData.SONumber”附近显然存在“语法错误”错误,我都无法解决而无法识别。有人可以看看我的大脑是否有一些东西没有处理吗?

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
4

1 回答 1

0

好吧,您的语法似乎遗漏了几件事。您缺少ON几个JOINs 的语法:

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
于 2012-10-11T00:14:13.100 回答