-1

我有两个字段,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 函数有关,但我不确定。

4

1 回答 1

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
于 2013-08-08T18:59:49.807 回答