IF OBJECT_ID ('dbo.varbin2hexstr') IS NOT NULL DROP FUNCTION dbo.varbin2hexstr GO
CREATE function varbin2hexstr( @bin varbinary(8000) )returns varchar(8000) as begin declare @re varchar(8000),@i int select @re='',@i=datalength(@bin) while @i0 select @re=substring('0123456789ABCDEF',substring(@bin,@i,1)/16+1,1) +substring('0123456789ABCDEF',substring(@bin,@i,1)%16+1,1) +@re ,@i=@i-1 -- return('0x'+@re) return @re end