declare @tblorderskq table (kqorderstatus int,otherpaytype varchar(1),ordernum int) insert into @tblorderskq select 1,'a',1 union all select 0,'b',1 union all select 2,'c',1 union all select 3,'d',1 union all select 0,'e',1 union all select 4,'f',1select * from @tblorderskq /* kqorderstatus otherpaytype ------------- ------------ 1 a 0 b 2 c 3 d 0 e 4 f */declare @orderno int set @orderno=1select top 6 isnull(case kqorderstatus when 0 then '' else otherpaytype end ,'') from @tblorderskq where ordernum = @orderno/* ac df */你看看处理前和处理后的结果就好理解了
isnull:如果查询语句返回空则用''代替
否则返回 字段 KQOrderStatus原来的值
isnull((select。),‘’)如果select语句得到的值是null的话,返回一个空格
declare @tblorderskq table (kqorderstatus int,otherpaytype varchar(1),ordernum int)
insert into @tblorderskq
select 1,'a',1 union all
select 0,'b',1 union all
select 2,'c',1 union all
select 3,'d',1 union all
select 0,'e',1 union all
select 4,'f',1select * from @tblorderskq
/*
kqorderstatus otherpaytype
------------- ------------
1 a
0 b
2 c
3 d
0 e
4 f
*/declare @orderno int set @orderno=1select top 6
isnull(case kqorderstatus when 0 then '' else otherpaytype end ,'')
from @tblorderskq where ordernum = @orderno/*
ac
df
*/你看看处理前和处理后的结果就好理解了