-
Notifications
You must be signed in to change notification settings - Fork 1
/
fn_abc_hexadecimal.txt
51 lines (40 loc) · 1.18 KB
/
fn_abc_hexadecimal.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/****** Object: UserDefinedFunction [dbo].[fn_abc_hexadecimal] Script Date: 11/30/2012 13:39:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Tim Braga
-- Create date: 11-07-2012
-- Description: Returns Binary as Hex
-- =============================================
CREATE FUNCTION [dbo].[fn_abc_hexadecimal]
(
@binvalue varbinary(255)
)
RETURNS varchar(1500)
as
BEGIN
declare @charvalue varchar(255)
declare @i int
declare @length int
declare @hexstring char(16)
select @charvalue = '0x'
select @i = 1
select @length = datalength(@binvalue)
select @hexstring = '0123456789abcdef'
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
RETURN @charvalue
END