次のクエリを SQL Server 2008 で機能させようとしています。「ピボットテーブル付近の構文が正しくありません」というエラー メッセージ (最後に表示されます) が返されます。誰でもエラーを見つけるのを手伝ってもらえますか?
SELECT * FROM (
(SELECT p_id, [InfoSec].[dbo].[tb_incidents_secureworks].[classification],
DATENAME(mm, occurrence) as [month]
FROM [InfoSec].[dbo].[tb_incidents_secureworks]
WHERE [InfoSec].[dbo].[tb_incidents_secureworks].[type] = 'Security Incident'
AND occurrence >= DATEADD(mm, DATEDIFF(mm,0,DATEADD(mm,-12,getdate())), 0)
AND occurrence < DATEADD(mm, DATEDIFF(mm,0,DATEADD(mm,0,getdate())), 0)
UNION ALL
SELECT p_id, [InfoSec].[dbo].[tb_incidents].[classification],
DATENAME(mm, occurrence) as [month]
FROM [InfoSec].[dbo].[tb_incidents]
WHERE (occurrence >= DATEADD(mm, DATEDIFF(mm,0,DATEADD(mm,-12,getdate())), 0)
AND occurrence < DATEADD(mm, DATEDIFF(mm,0,DATEADD(mm,0,getdate())), 0)))
AS SourceTable
PIVOT (
COUNT(p_id)
FOR [month] in ([August],[September],[October],[November],[December],[January],[February],[March],[April],[May],[June],[July])
) AS PivotTable