Thursday, February 27, 2014

Strange problem with case statement


I'm using Dynamic sql. Table variable will not work. Why it is showing unexpected result using temp table.



Then you did not understand Ganesh's answer. He showed you that with data you posted, your SELECT statement gave the expected output. He only used a table variable to put your data into SQL.


From this we can conclude that whatever issue you have it is with something

you are not telling us.


Oh, some people told you to use the PIVOT operator. Don't listen to them. Your code is the right way to do a pivot. The PIVOT operator does not give much benefit and puts you in a straight-jacket. Using CASE like you did gives more flexible. And it runs on other engines too.





Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

No comments:

Post a Comment