TSQL and the case when with a few points?

I have several conditions, and the result for them should be the same. I searched the web and found things like this:

CASE ProductLine WHEN 'R' THEN 'Road' WHEN 'M' THEN 'Mountain' WHEN 'T' THEN 'Touring' WHEN 'S' THEN 'Other sale items' ELSE 'Not for sale' END 

This is good, but not what I need, for me it looks more like R, M, T and S have the same result, but A, B, C, D, for example, do not. How can I do it? I cannot contact OR, or at least I failed :). Something like this maybe?

 CASE ProductLine WHEN 'R' OR 'M' OR ... THEN 'Road' ELSE 'Not for sale' END 
+6
source share
1 answer

Go to the "search" for the CASE expression . You have a "simple" CASE expression above

 CASE WHEN ProductLine IN ('R', 'M', ...) THEN 'Road' ELSE 'Not for sale' END 

In the MSDN link above:

 Simple CASE expression: CASE input_expression WHEN when_expression THEN result_expression [ ...n ] [ ELSE else_result_expression ] END Searched CASE expression: CASE WHEN Boolean_expression THEN result_expression [ ...n ] [ ELSE else_result_expression ] END 
+7
source

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


All Articles