0 votes
1 view
in SQL by (6.1k points)

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?

1 Answer

0 votes
by (12.7k points)
edited by

You could just do the following:

SELECT
    *
FROM
    Table
WHERE
    (@booleanResult = 1
    AND Column1 = 'value1')
OR
    (@booleanResult = 0
    AND Column1 = 'value1'
    AND Column2 = 'value2')

Hope this helps!

Want to know more about SQLJoin this SQL training course and certification by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 11, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...