Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIF statement in SQL Server 2005

Does IIF statement exists in all version of SQL Server ?

I have checked a tutorial on MSDN.

But when I tried to run this code on my machine

DECLARE @newDate datetime
SET @newDate =  CONVERT(varchar, {fn NOW()}, 111)
SELECT IIF(@newDate > '2010/12/2', 'Greater', 'smaller')

But I am getting error of "Incorrect syntax near '>'."

Can someone provide me an example in SQL Server 2005 for the existence of the IIF statement?

like image 842
Zerotoinfinity Avatar asked Dec 07 '10 08:12

Zerotoinfinity


People also ask

What is IIF function in SQL Server?

IIF is a shorthand way for writing a CASE expression. It evaluates the Boolean expression passed as the first argument, and then returns either of the other two arguments based on the result of the evaluation.

When was IIF introduced in SQL Server?

IIF was introduced in SQL Server 2012. IIF is a shorthand way for writing a CASE Expression. IIFs can only be nested up to a maximum level of 10. From the types of "true value" and "false value," the IIF function returns the data type with the highest precedence.

What is IIF statement?

You use IIf to determine if another expression is true or false. If the expression is true, IIf returns one value; if it is false, IIf returns another. You specify the values IIf returns. See some examples. Syntax.


1 Answers

That IIF statement only exists in MDX - the query language for SQL Server Analysis Services - the datawarehousing side of SQL Server.

Plain T-SQL does not have an IIF statement.

The best you can do in T-SQL is use the CASE.... WHEN... THEN... statement.

like image 116
marc_s Avatar answered Nov 02 '22 21:11

marc_s