IIF() : Returns one of two values depending on condition is True or False
Syntax:IIF (condition, if true, if false).It can be used instead of CASE when we want to check a condition and based on the output (True/False) pick one value/column.
Eg: SELECT IIF (0 > 1,'TRUE','FALSE') AS CASE_REPLACE;
Output:
CASE_REPLACE
------------
FALSE
If we use CASE then above scenario would be
like this:
SELECT (CASE WHEN 0>1
THEN 'TRUE' ELSE 'FALSE' END) AS [CASE_OUPUT]
Output:
CASE_OUPUT
----------
FALSE
IIF looks
comparatively simple, but CASE has it’s on edge over IIF as it can be used to
evaluate more condition by using ‘WHEN-THEN’
No comments:
Post a Comment