是否可以在 DATEADD 区间参数中使用 case 表达式?
select DATEADD(case c1 when 1 then HOUR when 2 then DAY end, c2, date) from T
Update1:抱歉,我想在where子句中使用它
select * from T where DATEADD(case c1 when 1 then HOUR when 2 then DAY end, c2, date) < GETDATE()
也许还有另一种选择。
提前致谢
最佳答案
试试下面..
select * from T
where case c1 when 1 then DATEADD(HOUR, c2, date)
when 2 then DATEADD(DAY, c2, date)
end < Getdate()
关于sql - 在 DATEADD 间隔中使用 case 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32647676/