SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Куракин В.А.
-- Create date: 27.10.2016
-- Description: Создание рандомного слова из русских букв заданной длины
-- =============================================
CREATE PROCEDURE usp_GetRandomWord
@letterCounr int = 10
AS
BEGIN
DECLARE
@i int,
@min bigint, @max bigint, @rand as bigint,
@onechar1 nvarchar(1), @onechar2 nvarchar(1), @return nvarchar(255)
Set @return = ''
SELECT @min = 1, @max = 33
set @i = 0
while (@i < @letterCounr)
BEGIN
while (@onechar1 is null)
begin
SELECT @rand = ((@max + 1) - @min) * Rand() + @min
select @onechar1 = [letter] from [PDGP].[dbo].[Letter]
where ID = @rand and isHard = 0 and isvocular = 0
end
set @return = @return + @onechar1
set @i = @i + 1
while (@onechar2 is null)
begin
SELECT @rand = ((@max + 1) - @min) * Rand() + @min
select @onechar2 = [letter] from [PDGP].[dbo].[Letter]
where ID = @rand and isHard = 0 and isvocular = 1
end
set @return = @return + @onechar2
set @i = @i + 1
set @onechar1 = null
set @onechar2 = null
END
select @return
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Куракин В.А.
-- Create date: 27.10.2016
-- Description: Создание рандомного слова из русских букв заданной длины
-- =============================================
CREATE PROCEDURE [dbo].[usp_GetRandomWord]
(
@letterCount int = 10
, @out nvarchar(10) output
)
AS
BEGIN
DECLARE
@i int,
@min bigint, @max bigint, @rand as bigint,
@onechar1 nvarchar(1), @onechar2 nvarchar(1), @return nvarchar(255)
Set @return = ''
SELECT @min = 1, @max = 33
set @i = 0
while (@i < @letterCount)
BEGIN
while (@onechar1 is null)
begin
SELECT @rand = ((@max + 1) - @min) * Rand() + @min
select @onechar1 = [letter] from [PDGP].[dbo].[Letter]
where ID = @rand and isHard = 0 and isvocular = 0
end
set @return = @return + @onechar1
set @i = @i + 1
while (@onechar2 is null)
begin
SELECT @rand = ((@max + 1) - @min) * Rand() + @min
select @onechar2 = [letter] from [PDGP].[dbo].[Letter]
where ID = @rand and isHard = 0 and isvocular = 1
end
set @return = @return + @onechar2
set @i = @i + 1
set @onechar1 = null
set @onechar2 = null
END
set @out = @return
END