Use if-else logic in where where in T-SQL

Is there a way to use if-else logic in the where clause in T-SQL? or do I need to implement logic using a subquery?

+3
source share
2 answers

Use Case

(case foo when bar then baz else fizz end)
+4
source

You can use the case statement in the where clause, but it can cause performance problems, so you can try a different approach if you have a large dataset. A correlated subquery would not be a good alternative approach; view or CTE may be.

+4
source

Source: https://habr.com/ru/post/1752328/