Skip to content
Advertisement

Dynamically name a column based on a WHERE condition

Objective:

I am running a query on a weekly basis and would like one of my column to return the ISO_WEEK number with the prefix ‘W’. For example: W1.

More specifically, I would like to reproduce the following condition into a column name.

Main Query is:

Advertisement

Answer

SQL Server is declarative by design and does not support macro substitution. This leaves you with Dynamic SQL such as …

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