Skip to content
Tako Lee edited this page Feb 16, 2014 · 9 revisions
  • WHEN/THEN keyword in the same line, WHEN keyword indent from 0 to n
SELECT productnumber, 
       name, 
       'Price Range' = CASE  
                           WHEN listprice = 0 THEN 'Mfg item - not for resale'  
                           WHEN listprice < 50 THEN 'Under $50'  
                           WHEN listprice >= 50  
                                AND listprice < 250 THEN 'Under $250'  
                           WHEN listprice >= 250  
                                AND listprice < 1000 THEN 'Under $1000'  
                           ELSE 'Over $1000'  
                       END  
FROM   production.product  
ORDER  BY productnumber; 
  • THEN keyword in new line, WHEN keyword indent from 0 to n
SELECT productnumber, 
       name, 
       'Price Range' = CASE  
                         WHEN listprice = 0  
                         THEN 'Mfg item - not for resale'  
                         WHEN listprice < 50  
                         THEN 'Under $50'  
                         WHEN listprice >= 50  
                              AND listprice < 250  
                         THEN 'Under $250'  
                         WHEN listprice >= 250  
                              AND listprice < 1000  
                         THEN 'Under $1000'  
                         ELSE 'Over $1000'  
                       END  
FROM   production.product  
ORDER  BY productnumber;  

Clone this wiki locally