Sunday, February 19, 2012

IIF Function

I've been looking at the online help and it appears that
this statement should function as follows:
Select IIf(1 > 0 , 'Yes', 'No')
If 1 is greater than 0, Yes should be returned, if not
then No
Sql returns an error message: Incorrect syntax near '>'
Any Ideas?
ThanksYou must be looking at help for MS Access or Excel or something. There is
no such thing as IIF in SQL Server. Maybe try CASE:
SELECT CASE WHEN 1 > 0 THEN 'Yes' ELSE 'No' END
"Raghib" <anonymous@.discussions.microsoft.com> wrote in message
news:100801c4f1fe$f73d1860$a301280a@.phx.gbl...
> I've been looking at the online help and it appears that
> this statement should function as follows:
> Select IIf(1 > 0 , 'Yes', 'No')
>
> If 1 is greater than 0, Yes should be returned, if not
> then No
> Sql returns an error message: Incorrect syntax near '>'
> Any Ideas?
> Thanks
>|||If you search for IIF in SQL Server Books Online, you will indeed find it.
However, you have to look at the title (or location) and realize it is for
Analysis Services only.
This is not a TSQL function, but rather an MDX function.
--
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"Aaron Bertrand [MVP]" <aaron@.TRASHaspfaq.com> wrote in message
news:%23GAGeFg8EHA.2600@.TK2MSFTNGP09.phx.gbl...
> You must be looking at help for MS Access or Excel or something. There is
> no such thing as IIF in SQL Server. Maybe try CASE:
> SELECT CASE WHEN 1 > 0 THEN 'Yes' ELSE 'No' END
>
>
> "Raghib" <anonymous@.discussions.microsoft.com> wrote in message
> news:100801c4f1fe$f73d1860$a301280a@.phx.gbl...
>> I've been looking at the online help and it appears that
>> this statement should function as follows:
>> Select IIf(1 > 0 , 'Yes', 'No')
>>
>> If 1 is greater than 0, Yes should be returned, if not
>> then No
>> Sql returns an error message: Incorrect syntax near '>'
>> Any Ideas?
>> Thanks
>

No comments:

Post a Comment