Saturday, September 8, 2018

Simplify the Use of OR Statement in SQL Formula

The use of OR Statement in a search is commonly used with CASE-WHEN Statement. This helps in comparing multiple values of certain fields. To shorten the formula without affecting the result, use the IN function. For example,


Instead of:

CASE WHEN {custentity_strat_house.id}=26 OR {custentity_strat_house.id}=2 OR {custentity_strat_house.id}=27} OR {custentity_strat_house.id}=28 THEN 'other consulting' ELSE {custentity_strat_house} END

 

Rewrite the above formula as:

CASE WHEN {custentity_strat_house.id} IN (26,2,27,28) THEN 'other consulting' ELSE {custentity_strat_house} END



 

No comments:

Post a Comment