The reason the random number is not changing is you have to change the seed(starting value) that the random function uses to generate the random number. The random number is not truly random as it is based on a seed.
This example uses a seed (@counter) and generates 5 random numbers, each time through the loop it adds 1 to @counter thus changing the seed.
DECLARE @counter smallint
SET @counter = 1
WHILE @counter < 5
BEGIN
SELECT RAND(@counter)
SET @counter = @counter + 1 -- CHANGING THE SEED VALUE
END
GO
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.