1
我有以下查詢錯誤樞軸查詢
DECLARE @query NVARCHAR(4000)
DECLARE @Days NVARCHAR(4000)
SELECT @Days = STUFF((SELECT DISTINCT
'],[' + ltrim(str(datepart(dw,visitdate)))
FROM mktPlanHospitals
ORDER BY '],[' + ltrim(str(datepart(dw,visitdate)))
FOR XML PATH('') ), 1, 2, '') + ']'
SET @query =
'SELECT * FROM
(
SELECT DoctorID,datepart(dw,visitdate),DoctorID
FROM mktPlanHospitals
)t
PIVOT (SUM(DoctorID) FOR datepart(dw,visitdate)
IN ('[email protected]+')) AS pvt'
EXECUTE (@query)
這是給我的錯誤
Incorrect syntax near '('.
我下面從http://dotnetgalactics.wordpress.com/2009/10/23/using-sql-server-20052008-pivot後的問題-on-未知數柱動態樞軸的。我怎麼能修改得到resut – Tassadaque
我會刪除ORDER BY中的YEAR()函數,我不認爲這需要在那裏。 – Jacob
感謝您的回覆。我更新了查詢並獲得錯誤的語法錯誤。請參閱更新的問題 – Tassadaque