Possible Duplicate:
Creating Nondeterministic functions in SQL Server using RAND()
I need to generate some random nvarchar in a function. So I create this function :
CREATE FUNCTION [dbo].[sfp_GenerateRandomString]
(@length int) -- Length of string
RETURNS NVARCHAR
AS
BEGIN
DECLARE @random NVARCHAR(25) = ''
while @length > 0
begin
set @random = @random + nchar((cast(rand()*1000 as int)%26)+97)
set @length = @length-1
end
return @random
END
But it doesn't work because the RAND() function is forbidden in SQL function who have to be DETERMINISTIC. And RAND() is NONDETERMINISTIC.
So my question is how to generate random number in this case? Thanks.