TDM @IF(bool, tExp, fExp)@ Fucntion Parsing Both True and False Expressions

Document ID : KB000113500
Last Modified Date : 10/09/2018
Show Technical Document Details
Issue:
When attempting to run an IF function within a generator, both the TRUE and the FALSE expressions will be evaluated, which could result in errors being thrown depending on the logic/requirements of the IF.

For example:
@IF(~ImportantTableDoesNotExist~, @execsql(Pprofile,select * from OTHERTABLE)@, @execsql(Pprofile,select * from ImportantTable))@

In this case, "ImportantTable" doesn't exist, so selecting from said table will return an error. One wouldn't expect an error to occur in this scenario since most programming languages/logic will only execute the appropriate statement after an IF had been evaluated.
Cause:
TDM variable/function parser works from the inside out. It must resolve all variables and functions so that the proper data is generated as expected once all functions return at the top level. In the case of an IF function, BOTH the TRUE and FALSE expressions will be evaluated before the Boolean value is evaluated. This is working as designed.

The parser works like this for all functions and is not limited to the IF function.
Resolution:
In an example such as the one provided above, appropriate checks should be performed within the SQL syntax and not rely on TDM's IF function to only evaluate one or the other expression.