I’m getting a very unexpected error, and I’m not sure if it is due to compatibility settings or something silly. (I’m using SQL Server 2008 R2.) My query fails on the aggregate inside the pivot.
Snippet:
select * from @sales
pivot
(
sum(Amount)
for Quarter
in (Q1, Q2, Q3, Q4)
) as p
Incorrent syntax on the line sum(Amount)
Works for me for table definition
so presumably it is a compatibility level issue. You can do
For a solution that will work under SQL Server 2000 compatibility mode.