I try to use IIF() function in SELECT statmenmt in a store procedure
difination.
SELECT iif( month(ref_date)=1 , 1 , 0 )
FROM MyTable
But the system always show me
Incorrect syntax near '='
What's the corect syntax of iif function?
Thank you.Hi!
There is no IIF function in T-SQL, but you can use CASE expression instead.
Do please look for the syntax in Books OnLine.
--
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com
"Xiaotao, Lu" <luxiaotao@.hotmail.com> wrote in message
news:eLm9ieCAEHA.1608@.TK2MSFTNGP11.phx.gbl...
> I try to use IIF() function in SELECT statmenmt in a store procedure
> difination.
> SELECT iif( month(ref_date)=1 , 1 , 0 )
> FROM MyTable
> But the system always show me
> Incorrect syntax near '='
> What's the corect syntax of iif function?
> Thank you.
>|||Use CASE:
SELECT CASE WHEN MONTH(ref_date)=1 THEN 1 ELSE 0 END
FROM MyTable
--
David Portas
SQL Server MVP
--
Thursday, March 8, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment