我有一个存储过程,我在其中传递了 0、1、2 的值。
0= 无,其中 1= 持续时间 >0 2= 持续时间 =0
select * from Table where case when @duration =1 then Duration else 1 end >0
这有效,但是我无法让其他值起作用。我已经尝试了 3 个 case 语句,但只有最后一个有效。
我怎样才能得到一个动态的 where 语句来处理 3 个值?
我不会使用case
声明。只需使用布尔逻辑
select *
from table
where (@duration = 0)
or (@duration = 1 and duration > 0)
or (@duration = 2 and duration = 0)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3741 次 |
最近记录: |