Example for IIF doesnt work when copy/paste

From SSMS when I enter

DECLARE @a int = 45, @b int = 40;
SELECT IIF ( @a > @b, 'TRUE', 'FALSE' ) AS Result;

I get
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '>'.

But I copy pasted directly out of https://docs.microsoft.com/en-us/sql/t-sql/functions/logical-functions-iif-transact-sql

Why is that ?? Thanks

Most probably you are using a version of SQL that is too old. IIF() was introduced in SQL 2012

Check your version:

SELECT @@version
1 Like

Yes, my version is 2008 - waiting to be updated.... Thanks !!!

2008 supports CASE:

DECLARE @a int = 45, @b int = 40;

SELECT CASE WHEN @a > @b THEN 'TRUE' ELSE 'FALSE' END AS Result;
1 Like

Thanks so much !!!