我尝试运行此查询时出现上述错误
DECLARE @ColumnNames NVARCHAR(MAX)=''
DECLARE @SQL NVARCHAR(MAX)=''
SELECT @ColumnNames=Stuff((SELECT DISTINCT ',' + Quotename([COL1])
FROM table1
FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '')
SET @SQL = 'SELECT * FROM
( SELECT
[COL1]
,[COL2]
FROM
FROM table1 ) AS BaseData
PIVOT(
COUNT([COL2])
FOR [COL1]
IN('+@ColumnNames +
')
) As PivotTable'
EXECUTE sp_executesql @SQL
请问我做错了什么?
答案 0 :(得分:3)
查询中有两个from
。
FROM FROM table1 --change this