34,575
社区成员
发帖
与我相关
我的任务
分享
create table #temp
(id INT, code nvarchar(2))
insert into #temp
select 1, '0' UNION
select 2, '1' UNION
select 3, '0' UNION
select 4,'22' UNION
select 5,'0'
update #temp set code = '' where code = '0'
select * from #temp where code = 0
drop table #temp
use tempdb
go
create table a (bz char(1),bh varchar(20)) --BZ字段描述是标识,BH字段描述是编号
go
insert into a (bh) values ('085')
insert into a values ('','247') --在数据迁移或者同步过程中让人忽略的关键数据
insert into a values ('0','122')
go
create table aa (zhekou1 real,bh varchar(20)) --zhekou1 字段描述是折扣
go
insert into aa values (0.01,'085')
insert into aa values (0.01,'122')
insert into aa values (0.01,'247')
go
--TSQL 1
select case isnull(B.BZ,0)
when '0' then ISNULL(c.zhekou1,其他表的另一个折扣)
when '1' then 0 else 1 end data
from a b
join aa c on b.bh=c.bh
--TSQL 2
select case isnull(BZ,0)
when '0' then 0.1
when '1' then 0 else 1 end data
from a
SELECT CAST('' AS int)
SELECT CASE WHEN ''=0 THEN 1 ELSE 0 END