Ironside Tech Tip: Which Logic Statement is Better to Use – Case or If?
The Preferred Syntax to use in Cognos and Why
Cognos is not a programming language, but it does allow programmable syntax such as a case or an if logic statement. The question is, which is the preferred syntax to use and why?
Generally speaking, the answer is that it does not matter. The best one to choose should be based on your brain’s ability to write and perceive the code one way or another. The best application, however is to use them as follows:
|if||Logical comparisons||if ( > 100|
|case||Character matching||case when = ‘Brazil’|
The possible exception to this is when comparing ranges of values. In this scenario, the if logic statement is a bit more cumbersome than using a case statement:
One last hint when using numerical comparisons; the between syntax with case is inclusive of the lowest and highest value by default (even down to floating point precision.) When using if, however the greater than or equal to operator is required (as shown above.)
For more details on Cognos syntax, sign up today for one of our excellent education classes. See our current schedule of instructor-led and on-site classes.