Is there a way to make a CASE statement with an IN clause?
SELECT CASE c.Number IN ('1121231','31242323') THEN 1 IN ('234523','2342423') THEN 2 END AS Test FROM tblClient c
Of course I can write the case condition multiple times, each time return one value. However, as I have many condition need to fit, say 100. It is not good to repeat case condition again and again.
Multiple conditions in CASE statementYou can evaluate multiple conditions in the CASE statement.
A CASE statement cannot return more than one value, it is a function working on one value.
The IN operator allows you to specify multiple values in a WHERE clause. The IN operator is a shorthand for multiple OR conditions.
Yes. You need to use the "Searched" form rather than the "Simple" form of the CASE
expression
SELECT CASE WHEN c.Number IN ( '1121231', '31242323' ) THEN 1 WHEN c.Number IN ( '234523', '2342423' ) THEN 2 END AS Test FROM tblClient c
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