post icon

How to use RAND SQL Function

The RAND() SQL function returns a float random number.

Many times is helpful to have an integer random number, inside a range of values, between a minumum and maximum numbers.

The following snippet shows hw to use the SQL random RAND function:

DECLARE @RdmNum float, @RdmInt int, @Max int, @Min int

-- Max value of random int
SET @Max = 15000
-- Min value of random int
SET @Min = 0

--RAND SQL function

SELECT @RdmInt = ((@Max + 1) - @Min) * @RdmNum + @Min

SELECT @RdmNum AS RandomNumber, @RdmInt AS RandomInteger
February 27th, 2009 @ 02:49

1 Comment

Leave a comment
  1. Maryanne
    February 16th, 2016 at 08:40 #

    I like the valuable information you provide in your articles.
    I will bookmark your blog and check again here
    regularly. I’m quite certain I will learn many new stuff right here!
    Good luck for the next!

Leave a Reply

Are you human? Time limit is exhausted. Please reload CAPTCHA.