I am writing a case statement where I need to check columns and assign a value . But what if a row qualifies for multiple cases ? For example in following table I want assign a bucket when COLA and/or COLB is null ; so in first case both are NULL , so how will I tell SQL case statement to assign "Both are NULL " when COLA and COLB are null. I can easily assign when COLA or COLB is null . At my work I am checking 8 columns , so I need to find every combination and right case for that ? There has to be an easy way .
**RowNumber COLA COLB Case**
1 Null Null **Both are NULL**
2 Null B A is null
3 A Null B is null
4 AA BB NULL
5 CC Null B is null
1条答案
按热度按时间5fjcxozz1#
Given you have 8 columns, you probably need to do something like this:
In the final select statement, you could make further alterations to present the results as you want.