Back
I want to have a conditional where clause that operates as so:
Select * From Table If (@booleanResult) Begin Where Column1 = 'value1' End Else Begin Where column1 = 'value1' and column2 = 'value2' End
Can anyone help with this?
You could just do the following:
SELECT *FROM TableWHERE (@booleanResult = 1 AND Column1 = 'value1')OR (@booleanResult = 0 AND Column1 = 'value1' AND Column2 = 'value2')
Hope this helps!
Want to know more about SQL ? Join this SQL training course and certification by Intellipaat.
30.9k questions
32.9k answers
500 comments
665 users