Hello, I almost 100% sure this is a issue with the programmer (me) but i would still like to get some other thoughts on this. I'm writing a pretty simple crosstab report that performs a count on a column called CustomerResponse which has 4 possible values; 0-3. There is also non-pivoted column called Appliction which shows the name of the application in which the customer responded to. When using the MS SQL 2005 pivot method the count for column 0 (meaning no response) shows a total of 0 for all applications; this is incorrect. I can run a simple select count(*) statement to verify that there is infact customer responses of 0 for some of applications. If switch to the MS SQL 2000 method of using case statements it works perfect. Is it possible that the PIVOT command cant pivot with an aggreate of count on values equal to 0 or is there an issue with my code? I would appreciate any help on this issue/topic? ThanksNot working properly PIVOT method:SELECT Category as 'Application',0 AS 'No Response',[1] AS 'Yes',[2] AS 'No',[3] AS 'Callback Requested'FROM (select category, customerResponsefrom HTCustomerSurveys) pPIVOT(COUNT (customerResponse)FOR customerResponse IN( [0],[1],[2],[3])) AS pvtORDER BY Category
Working CASE method:SELECT category, SUM(CASE customerResponse WHEN '0' THEN 1 ELSE 0 END) AS 'No Response', SUM(CASE customerResponse WHEN '1' THEN 1 ELSE 0 END) AS 'Yes', SUM(CASE customerResponse WHEN '2' THEN 1 ELSE 0 END) AS 'No', SUM(CASE customerResponse WHEN '3' THEN 1 ELSE 0 END) AS 'Callback Requested' FROM HTCustomerSurveysGROUP BY categoryorder by category