在 where 子句中使用两个日期之一

Use one of two dates in where clause

我需要删除 table 中 CreatedDate 或 ModifiedDate 大于 x 的所有记录。逻辑如下:

未正确应用 if/else 语句。

delete * from table where
-- how to implement the following
if ModifiedDate is not null then ModifiedDate < GETDATE() - 30
else CreatedDate < GETDATE() - 30

用例陈述

Delete * From tableX
CASE WEHN  ModifiedDate is not null and < Getdate() - 30 THEN -- your logic
Else -- CreateDate < Getdate() - 30 END

使用这个 where 子句:

where coalesce(ModifiedDate, CreateDate) < dateadd(day, -30, getdate())