日期:2014-05-18  浏览次数:20378 次

求一个sql,望仁兄们帮助
如何在sql server中将一个ASCII 16进制的字符串装换为对应字符。
Declare @str varchar(50)
set @str='414243313233344B4A'

输出对应字符:ABC1234KJ




------解决方案--------------------
SQL code
Declare @str varchar(50),@result varchar(50)
set @str='414243313233344B4A'

select 
  @result=isnull(@result,'')+
  char(left(col,1)*16
  +case when isnumeric(right(col,1))=0 then ascii(right(col,1))-55 else right(col,1) end
  )
from(
select substring(@str,number*2+1,2) as col
from master..spt_values
where type='P' and number<len(@str)/2
) t

select @result as result
/**
result
--------------------------------------------------
ABC1234KJ

(1 行受影响)
**/