O'Reilly logo

Microsoft® SQL Server 2012 Unleashed by Alex T. Silverstein, Chris Gallelli, Paul T. Bertucci, Ray Rankins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The IIF Function

The IIF function in SQL Server 2012 is essentially a shorthand version of the CASE expression. The syntax is as follows:

IIF ( boolean_expression, true_value, false_value )

The Boolean expression passed as the first argument is evaluated, and the function returns the true_value if the Boolean expression is true; otherwise, the false_value is returned. The following is an example of the IIF function:

SELECT ProductID,       IIF(Rating > 3, 'Highly Rated', 'Poor Rating') AS RatingFROM production.ProductReview prGO/*  ProductID Rating----------- ------------        709 Highly Rated        937 Highly Rated        937 Poor Rating        798 Highly Rated*/

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required