
[dbo].[al_bi_bintohexstr]
create function [dbo].[al_bi_bintohexstr] ( @binvalue binary(16) ) returns nvarchar(64)
as
begin
declare @charvalue nvarchar(64)
declare @i int
declare @length int
declare @hexstring char(16)
DECLARE @verNum varchar(4)
select @charvalue = N'0x'
select @i = 1
select @length = datalength(@binvalue)
select @hexstring = '0123456789ABCDEF'
SELECT @verNum = CAST(SERVERPROPERTY('productversion') as VARCHAR)
IF left(@verNum,2) = '10'
set @charvalue = convert(nvarchar(64),@binvalue,1)
else
begin
while (@i <= @length)
begin
declare @tempint int
declare @firstint int
declare @secondint int
select @tempint = convert(int, substring(@binvalue,@i,1))
select @firstint = floor(@tempint/16)
select @secondint = @tempint - (@firstint*16)
select @charvalue = @charvalue +
substring(@hexstring, @firstint+1, 1) +
substring(@hexstring, @secondint+1, 1)
select @i = @i + 1
end
end
return (@charvalue)
end
GO