为了账号安全,请及时绑定邮箱和手机立即绑定

sql语句怎么实现动态条件

sql语句怎么实现动态条件

MMTTMM 2018-07-24 10:13:12
select * from T where operator = (case when @type = 0 then @o1 else is not null end) 主要是想根据@type 用不同的条件当@type = 0 时 operator = @o 否则 operator is not null 请问各位大侠SQL语句怎么写,最好不要用字符串拼接
查看完整描述

3 回答

?
MMMHUHU

TA贡献1834条经验 获得超8个赞

select * from T where (operator = @o1 and @type = 0 ) or ( @type <> 0 and operator is not null )

查看完整回答
反对 回复 2018-07-26
?
湖上湖

TA贡献2003条经验 获得超2个赞

定义一个临时变量,然后用if else去判断,然后把值放到sql语句里面执行

查看完整回答
反对 回复 2018-07-26
?
元芳怎么了

TA贡献1798条经验 获得超7个赞

(case when @type=0 then (case when operator=@o then 1 else 0 end) else (case when operator is not null then 1 else 0 end) end )=1

查看完整回答
反对 回复 2018-07-26
  • 3 回答
  • 0 关注
  • 2629 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信