在我的数据库表中,我有一些像上面的图像。
我想查看where子句中的一些条件。
我想通过网址检查
DemoOrPaid=PAID and ValidUpto=NULL => then Return 1
2。DemoOrPaid=PAID and ValidUpto=(NOT NULL) then compare with current date and check if ValidUpto<=GETDATE() => then Return 1
DemoOrPaid=DEMO and ValidUpto=NULL => then Return 0
DemoOrPaid=DEMO and ValidUpto=(NOT NULL) then compare with current date and check if ValidUpto<=GETDATE() => then Return 0
答案 0 :(得分:0)
如果要返回某些计算列,则可以使用以下内容:
select
case
when DemoOrPaid = 'PAID' and ValidUpto is null then 1
when DemoOrPaid = 'PAID' and ValidUpto is not null and ValidUpto <= getdate() then 1
when DemoOrPaid = 'DEMO' and ValidUpto is null then 1
else 0
end
实际上有点不清楚在您的条件未涵盖的情况下您想要返回什么。
答案 1 :(得分:0)
以下内容将返回匹配的所有行。
select * from Table where
(DemoOrPaid='PAID' and ValidUpto is NULL) or
(DemoOrPaid='PAID' and ValidUpto is NOT NULL and ValidUpto<=GETDATE()) or
(DemoOrPaid='DEMO' and ValidUpto is NULL) or
(DemoOrPaid='DEMO' and ValidUpto is NULL and ValidUpto<=GETDATE())