The IIF function is a shorthand version for the CASE
statement. The syntax for the IIF function is as follows:
IIF (boolean_expression, true_value, false_value)
The function
behaves exactly as it does in Microsoft Excel. If the Boolean expression
evaluates to true, the first value is return, and if it evaluates to false, the
second value is returned. The following script illustrates the use of the
function:
SELECT IIF
(1=1, 'True', 'False') Condition
Result
Condition
-------------
True
See the
other example
Select ID,Name, empAdd,
IIF (empAdd='Pune' , 'State : MH',
IIF (empAdd='Patna' , 'State : Bihar', 'Other')),
Mobile FROM [Test].[dbo].[EMP]
|
See the
output
No comments:
Post a Comment
If you have any doubt, please let me know.