用存储过程如何实现从表中取值出来,然后通过while循环依次取两位数转换为10进制?
例如:
@info取值结果为字符串:’414231323334353637383920’
首先,先通过函数substring截取2位字符,’41’,然后把41转换为10进制,
得65。最后通过SQL指令select char(65)转换后,对应结果为 ’A’。
然后,再截取2位字符,’42’, 然后把41转换为10进制,得65。最后通
过SQL指令select char(65)转换后,对应结果为 ’B’。
如此类推,直至全部转换后,把字符串加在一起,可得条码号 ’AB123456789’。
------解决方案--------------------
create table ascll(a varchar(10),b varchar(10))
如 a =41 b=65
create proc test
@info nvarchar(100)
as
begin
declare @value nvarchar(100)
declare @int int
set @value=''
set @int=0
while @int<LEN(@info)
begin
set @value=@value+(select b from ascll where a=substring(@info,@int,2))
set @int=@int+2
end
select @value
end
差不多就这样了 自己改改