Skip to content
Advertisement

Select certain column only if condition met

I want to have a select that will not have fixed number of columns. Column OptionalColumn should be selected only if variable @check = 1

This is what I had (syntax is bad but maybe it explains my problem)

It is crucial to have it only if @Check = 1 and not having it if @Check = 0. Is it doable?

Advertisement

Answer

You could do this with an IF ELSE block like this;

Change the variable from 0 to 1 for testing to see the change in number of columns.

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