Skip to content
Advertisement

IIF(…) not a recognized built-in function

I’m trying to use this in Microsoft SQL Server 2008 R2:

SET @SomeVar = @SomeOtherVar +
  IIF(@SomeBool, 'value when true', 'value when false')

But I get an error:

IIF(...) is not a recognized built-in function name

Is IIF() only compatible with a later version?

Is there an alternate function I can use?

Advertisement

Answer

IIF comes from SQL 2012. Before then, you can use CASE:

SET @SomeVar = @SomeOtherVar + CASE
 WHEN @SomeBool
 THEN 'value when true'
 ELSE 'value when false'
END
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement