Does anyone know what Im doing wrong? I get an error msg saying invalid use of RAND within a function. Thanks!
CREATE FUNCTION RandString
-- Input length of string to be returned
(@LenString int
)
RETURNS char(50)
AS
BEGIN
DECLARE @position int, @AtoZstring char(26), @ResultString char(50)
SET @position = 1
SET @AtoZstring='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
SET @ResultString=''
WHILE @position <= @LenString
BEGIN
SET @ResultString=@ResultString+SUBSTRING(@AtoZstring, round(1+rand()*26,0) 1)
SET @position = @position + 1
END
RETURN (@ResultString)
END
CREATE FUNCTION RandString
-- Input length of string to be returned
(@LenString int
)
RETURNS char(50)
AS
BEGIN
DECLARE @position int, @AtoZstring char(26), @ResultString char(50)
SET @position = 1
SET @AtoZstring='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
SET @ResultString=''
WHILE @position <= @LenString
BEGIN
SET @ResultString=@ResultString+SUBSTRING(@AtoZstring, round(1+rand()*26,0) 1)
SET @position = @position + 1
END
RETURN (@ResultString)
END