Skip to content
Advertisement

week number as column name

first of all my sql statement:

It creates this output: current output That far I´m happy with the results, but I would love now having the week number of each sub select as column name.

The output should look like this: needed output

Advertisement

Answer

On your existing query, you can change to use CASE statement or PIVOT

example below uses the CASE statement

And to have the week number as column name, you need to use Dynamic SQL. Check out sp_executesql

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