sql if用法?

来源:百度知道 编辑:UC知道 时间:2024/08/23 22:16:10
有一张表rbb 里面有scsj,ty,yy
把整张表输出 select * from rbb,我现在想输出时进行筛选 scsj<>24时TY等于空SCSJ=24时TY等于原有数值不变,其它都不变输出整张表!
下面的几个我都试了 说是少关键字 运行不了 这是为什么呢

if 是在存储过程中用的
在sql 中你可以用case 效果一样
例子:
select * from rbb
where case when scsj <> 24 then ty = null
else scsj = 24 then ty
end

if sc>24
begin
select * from rbb
end
此上是查询sc大于24的数据。。
后面的一样。。。

select * from rbb
where case when scsj <> 24 then ty = null
else scsj = 24 then ty
end

sql的select里没有if else,有类似的case when then else end
-------------------
select
scsj,
case scsj when 24 then ty
else null end as ty,
yy from rbb