Nesting level of IIF? + SQL Server 2012

Posted by Bandi under Sql Server category on | Points: 40 | Views : 155
IIF function can be nested in SQL Server 2012. We can replace IF..ElseIF.... kind of operation in T-SQL with Single SELECT statement by using IIF( condition, IIF( Condition, IIF ( condition, ... , ...)))


DECLARE @Percentage AS NUMERIC(5,2) = 75 
SELECT IIF(@Percentage >= 75, 'Distinction',
IIF(@Percentage>=60 AND @Percentage<75, 'First Pass',
IIF(@Percentage>=50 AND @Percentage<65, 'Second Pass',
IIF(@Percentage>=35 AND @Percentage<50, 'Third Pass', 'Fail'))))


NOTE: The nesting level of IIF fucntion is up to 10

Comments or Responses

Login to post response