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.
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 ENDDATEFROM YourTable; Once it is part of a statement, there is nothign wrong with your IIF statement. |
|
|
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 ENDDATEFROM PAEMPOS;Incorrect Syntax near '=' |
|
|
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 ENDDATEFROM PAEMPOS;Incorrect Syntax near '='
Are you on SQL 2012? The IIF function is available only 2012 or later. |
|
|
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 expressionSELECT CASE WHEN END_DATE='1753-01-01' THEN '1753-01-01' ELSE '2753-01-01' END AS ENDDATEFROM PAEMPOS; |
|
|
|
|
|
|
|