Blog Post

Why is my pivot query not returning any data? How to debug a PIVOT query

,

If you have a PIVOT query and it isn’t returning the data you expect, what can you do to troubleshoot it? The thing to do is to break it down into the constituent parts. First, lets take a look at a query and see what we can do to help.

If you have this query:

SELECT [1] AS Student1, [2] AS Student2, coalesce([3], 0) AS Student3 FROM (SELECT student_id, amount FROM [a]) as source PIVOT ( SUM(amount) FOR student_id in ([1],[2],[3]) ) as pv Step 1 - Do you have any actual data?

Original post (opens in new tab)

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating