我正在使用SQL Server 2008,并且希望将以下动态数据透视查询转换为静态数据透视。
<TextBlock Text="{local:CustomBinding Date}" />
我尝试进行以下查询,但是在DECLARE @cols AS NVARCHAR(MAX),
@query AS NVARCHAR(MAX)
SELECT
@cols = STUFF((SELECT ',' + QUOTENAME(Weeks)
FROM MyTestTable
GROUP BY Weeks
ORDER BY Weeks
FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '')
SET @query = 'SELECT Month_year, ' + @cols +
' FROM
(SELECT Month_year, weeks, Xcount
FROM MyTestTable) x
PIVOT
(SUM(xCount)
FOR Weeks IN (' + @cols + ')) p '
EXECUTE(@query);
枢纽语句(最后一行查询)处显示错误。
For weeks in ()
请帮助我。