I need help writing a CASE statement for a view, that converts a column differently based on the value of a different column. For example:
CASE b.Column1 WHEN 1 THEN 'No' ELSE 'Yes' END AS Yes_or_No
This is great, it converts Column1 from another table to a Column called ‘Yes_or_No’, which displays ‘No’ when Column1 is 1, and ‘Yes’ when Column1 is ‘0’ or NULL.
The problem is, I want this to occur only when another column in the view, Column2, has a value called ‘Dev’. So, if Column2 has a value of ‘Dev’, then the CASE statement above should take effect. If Column2 has a value of ‘Test’ or ‘Prod’, then I want ‘Yes_or_No’ to just be NULL.
An easy approach is nested case statements:
For more readability I wrote in Upper cases outer
caseand Lower cases inner one.