','附近的语法不正确。动态枢轴

时间:2019-07-16 16:21:28

标签: sql sql-server pivot

我正在尝试实施解决方案outlined in this article,但出现以下错误。由于此代码对我来说是新的,因此我很难找到令人讨厌的逗号。第10行是第一个WHERE语句。如果我突出显示并运行第1-11行,则不会出现任何错误。

“ Msg 102,第15级,状态1,第10行 ','附近的语法不正确。”

SELECT HydraBatch, MESOrderNumber, MaterialNumberInputOrOutputBatch, [Comment], [Line], [LineTechnician], [PartDescription], [PartNo], [ReasonId], [ReasontextText], [ReportedAt], [ReportedBy], [SignedOfByFinalizer], [SignedOfByQA], [SignedOffFinalizerAt], [SignedOffQAAt], [Station]
FROM
(
select vw_Base_Batch_Events.MESOrderNumber, vw_Base_Batch_Events.HydraBatch,vw_Base_Batch_Events.MaterialNumberInputOrOutputBatch, vw_PZD_Detail_DLG_Data.Entry,vw_PZD_Detail_DLG_Data.ColumnName,vw_PZD_Detail_DLG_Data.ColumnValue
FROM            vw_PZD_Detail_DLG_Data INNER JOIN
                         vw_Base_Batch_Events ON vw_PZD_Detail_DLG_Data.ReferenceInteger = vw_Base_Batch_Events.ReferenceInteger
where (EventType IN ("NONCONF", "REJECT", "SKIP")) AND (MachineNumber LIKE "5999%") AND (LogDate BETWEEN CONVERT(DATETIME, "2019-06-01 00:00:00", 102) AND CONVERT(DATETIME, "2019-06-30 00:00:00", 102))
) as PivotData
PIVOT
(max(MESOrderNumber),Max(HydraBatch), Max(MaterialNumberInputOrOutputBatch)
FOR ColumnName in ([Comment], [Line], [LineTechnician], [PartDescription], [PartNo], [ReasonId], [ReasontextText], [ReportedAt], [ReportedBy], [SignedOfByFinalizer], [SignedOfByQA], [SignedOffFinalizerAt], [SignedOffQAAt], [Station])
) as PivotResult
ORDER BY MESOrderNumber, HydraBatch

编辑:打印@SQL返回以下内容。

row_number()

0 个答案:

没有答案