41 lines
3.5 KiB
Transact-SQL
41 lines
3.5 KiB
Transact-SQL
USE [site_fuchs]
|
|
GO
|
|
/****** Object: UserDefinedFunction [dbo].[ott_20_randomStrings] Script Date: 02.12.2020 21:05:05 ******/
|
|
DROP FUNCTION [dbo].[ott_20_randomStrings]
|
|
GO
|
|
/****** Object: UserDefinedFunction [dbo].[ott_20_randomStrings] Script Date: 02.12.2020 21:05:06 ******/
|
|
SET ANSI_NULLS ON
|
|
GO
|
|
SET QUOTED_IDENTIFIER ON
|
|
GO
|
|
|
|
-- =============================================
|
|
-- Author: <Author,,Name>
|
|
-- Create date: <Create Date,,>
|
|
-- Description: <Description,,>
|
|
-- =============================================
|
|
CREATE FUNCTION [dbo].[ott_20_randomStrings]
|
|
(
|
|
@digits tinyint
|
|
)
|
|
RETURNS @RET TABLE
|
|
(
|
|
[s] varchar(5)
|
|
)
|
|
AS
|
|
BEGIN
|
|
|
|
DECLARE @new_sessionid varchar(36), @trys int, @chars varchar(100), @UPPER int, @LOWER int;
|
|
SELECT @chars = '012KLMN34STUVWEFGHIJXYZ567OPQR89ABCD';
|
|
SELECT @UPPER = LEN(@chars), @LOWER = 1;
|
|
|
|
INSERT INTO @RET
|
|
SELECT * FROM (SELECT TOP(20) SUBSTRING(SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1), 1, @digits) as id FROM (VALUES(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20)) vl(id))z WHERE LEN(id) = @digits;
|
|
|
|
|
|
RETURN
|
|
END
|
|
GO
|
|
ALTER AUTHORIZATION ON [dbo].[ott_20_randomStrings] TO SCHEMA OWNER
|
|
GO
|