Skip to content
Advertisement

In SQL Server: Create Pivot Table with each Date as a own column

I have a table containing 4 different identifiers, a date and a numeric column like:

from which I want to create a kind of pivot table like the following:

This should be created for past 10 days or so, so it CRUCIAL I don’t have to set the dates manually. I tried something with PIVOT but that didn’t work out so I switched to do the job with CASE WHEN like the following:

but that still doesn’t work out as I get

How would you guys approach this issue is CASE the right way to do it or rather use PIVOT somehow? Or is there any s

Advertisement

Answer

Seems like you are looking for a Dynamic Pivot

Example

Returns

EDIT – Last Update – Next time ask a new question

Returns

enter image description here

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement