答案 0 :(得分:4)
等效的sql命令是CASE语句:
例如:
declare @t table(id int identity,code varchar(25))
insert @t(code)
select 'A' UNION ALL
select 'B' UNION ALL
select 'C' UNION ALL
select 'D' UNION ALL
select 'E' UNION ALL
select 'F'
select * from @t
--
select id,code,
case id
when 1 then code++convert(varchar(10),id)
when 2 then code++convert(varchar(10),id)
else 'UNDEFINED-DECODE VALUE for id : '+convert(varchar(10),id)
end as DECODEDVALUE
from @t
--
返回此数据集:
id code DECODEDVALUE
----------- ------------------------- ------------------------------------------
1 A A1
2 B B2
3 C UNDEFINED-DECODE VALUE for id : 3
4 D UNDEFINED-DECODE VALUE for id : 4
5 E UNDEFINED-DECODE VALUE for id : 5
6 F UNDEFINED-DECODE VALUE for id : 6