CHOOSE and IIF functions are logical functions.
CHOOSE function returns the value at the specified index from the specified list.
IIF function performs the work of the IF ELSE statement with one command. If it’s true, do something, if it’s not true, do something else.
Let’s make examples for a better understanding of CHOOSE and IIF functions.
CHOOSE Function:
1 |
SELECT CHOOSE ( 2, 'A', 'B', 'C', 'D' ); |
1 2 3 |
SELECT CHOOSE([AddressID], 'A', 'B', 'C', 'D' ) FROM [AdventureWorks2012].[Person].[Address] Where [AddressID] BETWEEN 1 and 3 |
IIF Function:
1 |
SELECT IIF(1>2,'true','false') IsTrue; |