Click here to Skip to main content
15,903,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)

Hi,

 I am using pivot for cross tab results in which i need to generate the report.Am using the Count aggregate function in the Pivot query.So if the Count is greater than 0 then i need to print as 'Yes' otherwise 'No'.

Can anyone please help me how to use case statement over aggregate function in Pivot

Thanks in advance 

Shameer Khan 

Posted

Perhaps you could post the code you have written so far. It would help us provide the last step.
 
Share this answer
 
Hi,

you can not use case statement along with aggregate function in pivot.

refer the following URL :- http://technet.microsoft.com/en-us/library/ms177410.aspx

If you want to use case statement then you can use in actual select statement in which you have used pivot keyword. check the following syntax:-
SELECT 'Sun'=
case when [Sun]>0 then 'true' else 'false' end,
'Mon' =
case when [Mon]>0 then 'true' else 'false' end,
'Tue' =
case when [Tue]>0 then 'true' else 'false' end

FROM
(Select
Days, Cost
From
Product
)P
PIVOT(
Sum(Cost)

FOR
Days IN
(
[Sun],
[Mon],
[Tue]
)) AS PVT

This way you can use case statement in your query. :)

Thanks

Mehul Thakkar
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900