Skip to content
Advertisement

Convert different dates in date column to rows in SQL Server

I want to display different dates as columns from LOGDATE column.

Here are the details

My query:

This query returns this result:

Expected output format:

I have multiple types of SERVICE_TYPE and SERVICE_NAME, not just the three sown in the sample.

How can I get my expected output? Any help would be appreciated.

Advertisement

Answer

You can do conditional aggregation to pivot the data over a fixed list of logdates:


You can also use SQL Server’s PIVOT feature:

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