Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Intermediate
Apr 26, 2017

Using Boolean Logic Instead of CASE WHEN

Once you get the hang of the CASE WHEN SQL Statement it can be easy to overuse it. Sometimes you do not need to even use the CASE WHEN Statement at all and you could simply replace it with Boolean logic. Now Boolean logic isn't a predefined topic per se, just an implementation. Take for example this CASE WHEN Statement:

SELECT *
FROM Pricelist_March
WHERE price    CASE PriceID
    WHEN 0 THEN 300
    WHEN 1 THEN 400
  END
This can be replaced by the following:
SELECT *
FROM Pricelist_March
WHERE
  PriceID = 0 AND price    PriceID = 1 AND price
Hannes du Preez
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date