我想要检索DaysVisted在两个值之间的行,例如,如果@days是90,则获取DaysVisited在90到60之间的记录,如果@days是60,则获取DaysVisited之间的记录60和30sql server多案例where条款
下面的查询是不给我正确的记录:
declare @days int
set @days = 60
select * from table where
DaysVisited >=
CASE
when (@days = 90) then
when (@days = 60) then @days
when (@days = 0) then 0
END
我想是这样的:
declare @days int
set @days = 60
select * from table where
CASE
when (@days = 90) then DaysVisited >= 90 and DaysVisited <= 60
when (@days = 60) then DaysVisited >= 60 and DaysVisited <= 30
when (@days = 0) then 0
END
所以它只是始终是天与日 - 30? –
不总是,天也可以为零,这些可以改变 – Sami
只需添加第二个变量,并在那里放第二个限制? –