1
set ANSI_NULLS ON
2
set QUOTED_IDENTIFIER ON
3
go
4
5
-- =============================================
6
-- Author: HuntFox
7
-- Create date: 2005.11.23
8
-- Description: 十进制整型转二进制字符串(锁定字符串长的最小值)
9
-- =============================================
10
ALTER FUNCTION [dbo].[ToBinarySystemString]
11
(
12
@DecimalSystemInt int,
13
@BinarySystemStringLen int
14
)
15
RETURNS NVARCHAR(31)
16
AS
17
BEGIN
18
-- Declare the return variable here
19
declare @ResultVar varchar(31)
20
set @ResultVar=\'\'
21
while (@DecimalSystemInt<>0)
22
begin
23
set @ResultVar=@ResultVar+convert(char(1),@DecimalSystemInt%2)
24
set @DecimalSystemInt=@DecimalSystemInt/2
25
end
26
set @ResultVar=REVERSE (@ResultVar)
27
while (Len(@ResultVar)<@BinarySystemStringLen)
28
begin
29
set @ResultVar=\'0\'+@ResultVar
30
end
31
RETURN @ResultVar
32
END
33
34
35
36
37
38
39
40
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