CREATE FUNCTION [dbo].[CreateRandomString] (
@iRandLength AS SMALLINT
)
RETURNS VARCHAR(100)
AS
BEGIN
DECLARE @wPassword VARCHAR(100)
DECLARE @wCharacters VARCHAR(100)
DECLARE @wCount INT
SET @wCharacters = ''
-- load up numbers 0 - 9
SET @wCount = 48
WHILE @wCount <=57
BEGIN
SET @wCharacters = @wCharacters + Cast(CHAR(@wCount) AS CHAR(1))
SET @wCount = @wCount + 1
END
-- load up uppercase letters A - Z
SET @wCount = 65
WHILE @wCount <=90
BEGIN
SET @wCharacters = @wCharacters + Cast(CHAR(@wCount) as CHAR(1))
SET @wCount = @wCount + 1
END
-- load up lowercase letters a - z
SET @wCount = 97
WHILE @wCount <=122
BEGIN
SET @wCharacters = @wCharacters + Cast(CHAR(@wCount) as CHAR(1))
SET @wCount = @wCount + 1
END
SET @wCount = 0
SET @wPassword = ''
WHILE @wCount < @iRandLength
BEGIN
SET @wPassword = @wPassword + SUBSTRING(@wCharacters,CAST(CEILING((SELECT r FROM RandHelper)*LEN(@wCharacters)) AS INT),1)
SET @wCount = @wCount + 1
END
RETURN @wPassword
END
CREATE VIEW [dbo].[RandHelper]
-- 랜덤 문자열생성을 위한 핼퍼 View
AS
SELECT RAND( ) AS r
GO
'Developer > MS-sql' 카테고리의 다른 글
paging , sql 2012 Query ,효율적인 페이징 쿼리 (0) | 2020.06.08 |
---|---|
where 절에서 Case When 사용 /if 문처럼 쓰기 (0) | 2019.05.07 |
Azure : Iaas DB에서 Pass DB로 연결된서버 붙이는 방법 (0) | 2019.03.26 |
제약조건 수정 ,CONSTRAINT , default 값 수정 , 칼럼 변경 (0) | 2019.01.02 |
SET XACT_ABORT ON 의미,프로시져 작성 요령 (0) | 2018.12.11 |