我有两个字段Days_since_last_Open
(数字)和last_login_dt
(日期)。我想比较它们以及Days_Since_Last_Activity
中值较低的地方。要做到这一点,我在我的查询中有这个case语句:
Case
When c.Days_Since_Last_Open < DateDiff(d,a.last_login_dt,GETDATE())
Then c.Days_Since_Last_Open
When DateDiff(d,a.last_login_dt,GETDATE()) < c.Days_Since_Last_Open
Then DateDiff(d,a.last_login_dt,GETDATE())
End As Days_Since_Last_Activity
但是,没有任何内容填充到Days_Since_Last_Activity中。我的想法是在CASE语句中运行Datediff函数,但我不确定。
答案 0 :(得分:1)
我相信你的CASE
应该是这样的
CASE
WHEN c.Days_Since_Last_Open < DATEDIFF(d, a.last_login_dt, GETDATE())
THEN c.Days_Since_Last_Open
ELSE DATEDIFF(d, a.last_login_dt, GETDATE())
END AS Days_Since_Last_Activity