Is there any way to use if-else logic in where clause in T-SQL? or do I have to implement the logic by using subquery?
+4
A:
You can use a case statement in a where clause, but it can generate performance issues, so you may want to try a different approach if you have a large dataset. A correlated subquery would not be a good alternative approach; a derived table or CTE might be.
HLGEM
2010-06-29 19:23:27
+1 Actually, a CTE is a good way to go.
Rodrick Chapman
2010-06-29 19:27:26