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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With