❔ SQL Server | Can i use 'Case When' in Where Clause?
i ususally do it by create the query into the string like this
but it realyyyy hard to debug if the query is very long,
so anyone know the proper way to do it?
6 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
If you don't need a complex query plus a special reason then just use ORM. EFCore to go
I would do something like this with SQL in your case:
Btw, your post name is pretty confusing
i want to put it into sp so probably not using orm
i see,
my brain still processing but i bit understand ,so if it cant find the value it will goes to second operatos and because the statement is inside brackets it will not bother the other statment outside it
(product = @ProductFilterValue OR @ProductFilterValue is not null)
hahaha sry my grammar really bad, but ty a lot browThe answer: Yes
Good luck. I don't remember if the OR condition statement's order would affect performance. It's better to switch
to
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.