--> Title : varbinary转换成字符串
--> Author : wufeng4552
--> Date : 2009-12-15
declare @s varchar(20),@bin varbinary(1000)
select @s='www.CSDN.net',@bin=cast(@s as varbinary(1000))
declare @re varchar(1000),@i int
select @re='',@i=datalength(@bin)
while @i>0
begin
select @re=substring('0123456789ABCDEF',substring(@bin,@i,1)/16+1,1)+
substring('0123456789ABCDEF',substring(@bin,@i,1)%16+1,1)+@re
,@i=@i-1
end
select '0x'+@re
select cast(@s as varbinary(1000))
/*
--------------------------
0x7777772E4353444E2E6E6574
(1 個資料列受到影響)
*/
/*
--------------------------
0x7777772E4353444E2E6E6574
(1 個資料列受到影響)
*/