mardi 7 juin 2016

MSSQL WHERE with IF

I am trying to get a query that does the below:

SELECT * FROM Test
WHERE
IF Condition = True
    Column1 = 'This'
    Column2 = 'That'
ELSE
    Column3 = 'This'
    column4 = 'That'

The only thing I can find with If Conditions in a where clause are CASES. I have not been able to find an example that allows cases for multiple conditions.

So far I have had to achieve this by having the If outside of the SELECT statement and duplicating the statement but changing the WHERE clause.

Aucun commentaire:

Enregistrer un commentaire