When I do this:
select col1,case when [pivot1]=1 then '-' else '' end [pivot1],
case when [pivot2]=1 then '-' else '' end [pivot2]
from
(select col1,col2,col3 from tbl) as c
pivot
(sum(col3) for col2 in
([pivot1],[pivot2]))as pvt
Everything works fine.
When I do this:
select col1,[pivot1],[pivot2]
from
(select col1,col2,col3 from tbl) as c
pivot
(sum(case col3 when '-' then 1 else 0 end) for col2 in
([pivot1],[pivot2]))as pvt
I get the following error:
"Msg 156, Level 15, State 1, Line 31
Incorrect syntax near the keyword 'case'."
My intention is to write a single case statement rather than multiple ones for this conversion.
What am I doing wrong?