Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 What is wrong with this IIF statement?

Author  Topic 

erinwithane
Starting Member

2 Posts

Posted - 2014-06-09 : 10:02:57
Hi everyone,

Can anyone tell me what is wrong with this IIF statement? Why doesn't it like the '='?

IIF(END_DATE ='1753-01-01','2753-01-01',END_DATE) AS ENDDATE


Incorrect syntax near '='.

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-06-09 : 10:19:35
quote:
Originally posted by erinwithane

Hi everyone,

Can anyone tell me what is wrong with this IIF statement? Why doesn't it like the '='?

IIF(END_DATE ='1753-01-01','2753-01-01',END_DATE) AS ENDDATE


Incorrect syntax near '='.

That is only an expression. An expression can be part of a statement, but cannot stand on its own - for example:
SELECT IIF(END_DATE ='1753-01-01','2753-01-01',END_DATE) AS ENDDATE
FROM YourTable;
Once it is part of a statement, there is nothign wrong with your IIF statement.
Go to Top of Page

erinwithane
Starting Member

2 Posts

Posted - 2014-06-09 : 11:31:33
Hi James,

My expression was part of a statement. My apologies for not including the entire statement. Any other ideas?

SELECT IIF(END_DATE ='1753-01-01','2753-01-01',END_DATE) AS ENDDATE
FROM PAEMPOS;

Incorrect Syntax near '='
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-06-09 : 15:32:49
quote:
Originally posted by erinwithane

Hi James,

My expression was part of a statement. My apologies for not including the entire statement. Any other ideas?

SELECT IIF(END_DATE ='1753-01-01','2753-01-01',END_DATE) AS ENDDATE
FROM PAEMPOS;

Incorrect Syntax near '='


Are you on SQL 2012? The IIF function is available only 2012 or later.
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-06-09 : 15:34:00
If you are on an older version, use a case expression

SELECT CASE WHEN END_DATE='1753-01-01' THEN '1753-01-01' ELSE '2753-01-01' END AS ENDDATE
FROM PAEMPOS;
Go to Top of Page
   

- Advertisement -