【发布时间】:2022-01-24 20:49:10
【问题描述】:
我想在 Microsoft SQL Server 中编写我想要的嵌套 case 语句
case
when date 2 is null
then date 1
else date 2
end ---1st condition
并将此条件用作:
case
when condition1 is <= getdate()
and condition1 < getdate() + 14
then 'DUE'
else 'after .
我收到错误消息,无法完成我的案例陈述。
【问题讨论】:
-
您的“第一个条件”可以表示为
ISNULL(Date2, Date1)- 然后在您的CASE中使用它 -
" 收到错误消息" 那是什么错误?这也是
CASE表达式,而不是Case语句。 -
and condition1 < getdate() + 14无关紧要,因为如果第一行为真,则它始终为真
标签: sql sql-server