Is it possible to use a CASE without ELSE in WHERE clause like an IF? for put a condition or not.
Example
WHERE monto = 100
AND CASE WHEN @canal is not null
THEN canal = @canal
END
I ask this because I want to do this
WHERE monto = 100
IF (@canal is not null){
AND canal = @canal
}
You need to include this condition in the WHERE:
WHERE monto = 100 AND ( @canal IS NULL OR canal = @canal )
If it's actually in a stored-procedure it might be more efficient if you use an IF...ELSE around the different queries, one with this parameter and one without.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With