Working with the IIF Statement in T-SQL

Working with the IIF Statement in T-SQL

You can use the IIF statement to check quickly for conditions. For example:

DECLARE @Spy varchar(20) = '07' SELECT IIF(@Spy = '007', 'Bond, James Bond', 'Ernst Stavro Blofeld')

If the Spy Variable is 007, then it will return “Bond, James Bond.” If it is anything else, it will return the second part of the statement, which is: “Ernst Stavro Blofeld”


About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist