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_MarchWHERE price    CASE PriceID    WHEN 0 THEN 300    WHEN 1 THEN 400  ENDThis can be replaced by the following:SELECT *FROM Pricelist_MarchWHERE  PriceID = 0 AND price    PriceID = 1 AND price
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: