我有一个名为 ACTUALCLOSEDATE 的日期时间字段,当相应的字段名为 STATUSNUM = 0 时,该字段等于 9999-12-31 00:00:00。当 STATUSNUM 更改为 1(记录关闭时)时,ACTUALCLOSEDATE 的值为更改为当前日期时间。
在我的查询中,我想用 'Still Open' 替换 ACTUALCLOSEDATE 当它 = 9999-12-31 00:00:00 时的值,而我只想要日期。
我在下面尝试了错误的代码。想法?我不知道 IIF 是否可用 SQL 2008 r2,是吗?如果可以,我可以使用它吗?
/* This is what I need but it dosen't work in SQL 2008 R2 */
SELECT
IIF (YEAR(ACTUALCLOSEDATE)=9999, "Still Open", ACTUALCLOSEDATE) AS ActCloseDate,
FROM OPPORTUNITY
/* This dosen't work either */
SELECT
CAST YEAR(ACTUALCLOSEDATE)
WHEN 9999 THEN 'Still Open'
ELSE ACTUALCLOSEDATE
END AS Act_Close,
FROM OPPORTUNITY