SQL ten random number (lowercase letters + data)

USE [TEST]
GO
/****** Object: UserDefinedFunction [dbo].[RANDTENNUMS] Script Date: 2019/7/23 15:40:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE function [dbo].[RANDTENNUMS]()
returns varchar(10)
as
begin
DECLARE @i int
DECLARE @flag int
DECLARE @SerialNumber nvarchar(20)
DECLARE @RANDS Numeric(38,38)
--初始化设定
SET @i=1
SET @SerialNumber = ''

- generating a random code 10
the WHILE @i <. 11
the BEGIN
- arranged randomly, randomly selects the letters (case) or digital
the SELECT @RANDS = RAND_A the FROM [the dbo] [VW_RAND].
The SET @ In Flag = ceiling (@RANDS * 3)

In Flag @ =. 1 the IF
the BEGIN
- random letters (capital removed uppercase O)
. @RANDS the SELECT = RAND_A the FROM [the dbo] [VW_RAND]
the WHILE char (65 + ceiling (@RANDS * 25)) = 'O'
the BEGIN
the SELECT @ = RAND_A the FROM Rands [the dbo] [VW_RAND].
the END
the SELECT @ @ SerialNumber = SerialNumber char + (65 + ceiling (@RANDS * 25))
the END
the else IF in Flag @ 2 =
the begin
- random letters (lowercase removed lowercase o)
= RAND_A the FROM @RANDS the SELECT [the dbo]. [VW_RAND]
the WHILE char (97 + ceiling (@RANDS * 25)) = 'O'
the BEGIN
the SELECT @RANDS = RAND_A the FROM [the dbo]. [VW_RAND]
the END
SELECT @ = @ SerialNumber + char SerialNumber (97 + ceiling (@RANDS * 25))
End
the else the begin
- random number of random numbers 1 to 9 (integer)
WHILE cast(ceiling(@RANDS * 9) as varchar(1)) = '0'
BEGIN
SELECT @RANDS = RAND_A FROM [dbo].[VW_RAND]
END
SELECT @RANDS = RAND_A FROM [dbo].[VW_RAND]
select @SerialNumber=@SerialNumber+cast(ceiling(@RANDS * 9) as varchar(1))
end

- for the next cycle
the SET @ @ I = I +. 1
the END
the RETURN @SerialNumber;
the END

Guess you like

Origin www.cnblogs.com/hEnius/p/11232471.html
Recommended