I have a SELECT query where the result of the second CASE statement may depend on the result of the first CASE statement - something like:
SELECT ...,
CASE
WHEN dbo.Table1.Description LIKE '%car%' THEN 'Car'
WHEN ...
ELSE 'Unclassified'
END AS Product,
CASE
WHEN dbo.Table2.Description LIKE '%my%brand%' THEN 'Branded'
WHEN Product='Unclassified' THEN 'Unclassified'
ELSE 'Generic'
END AS Brand,
...
FROM ...
If the brand is “unclassified”, if the request cannot find the brand name in the description column, as well as in the column “Product”, the value “Unclassified” is indicated. At the moment, this expression only ever displays the branded brands "Branded" or "Generic". Even when Product is “Unclassified,” it still gives “Generic,” which is not the result I need.
Any ideas?
source
share