mysql - SQL case statment - Multiple conditions -


i writing case statement need check columns , assign value . if row qualifies multiple cases ? example in following table want assign bucket when cola and/or colb null ; in first case both null , how tell sql case statement assign "both null " when cola , colb null. can assign when cola or colb null . @ work checking 8 columns , need find every combination , right case ? there has easy way .

**rownumber     cola                  colb                case** 1                   null                  null               **both null**  2                   null                  b                        null 3                                   null                 b null  4                   aa                bb                   null 5                   cc                null                 b null  

given have 8 columns, need this:

with t (     select         case when (cola null , colb null , colc null , cold null ,                     cole null , colf null , colg null , colh null) 'all' else '' end [all],         case when cola null 'a' else '' end [a],         case when colb null 'b' else '' end [b],         case when colc null 'c' else '' end [c],         case when cold null 'd' else '' end [d],         case when cole null 'e' else '' end [e],         case when colf null 'f' else '' end [f],         case when colg null 'g' else '' end [g],         case when colh null 'h' else '' end [h]                      <tablename>)                                  select      case when [all] = 'all' 'all null'     else [all] + ',' + + ',' + b + ',' + c + ',' + d + ','                 + e + ',' + f + ',' + g + ',' + h + ' null'  end t 

in final select statement, make further alterations present results want.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -