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语句怎么写,最好不要用字符串拼接
select * from T where (operator = @o1 and @type = 0 ) or ( @type <> 0 and operator is not null )
定义一个临时变量,然后用if else去判断,然后把值放到sql语句里面执行
你这个是写了一个sql语句啊,并没有拼接sql
我写的那句有问题,所以来请教
@Jxj: 有什么问题,直接保存还是,参数没有传入对?
(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
DECLARE int @a
SET @a=case when @type = 0 then @o1 else is not null end
select * from T where operator =@a
if(@type = 0)
begin
select * from T where operator=@o1
end
else
begin
select * from T where operator is not null
end
分开来写.
楼上正解