Vignesh M Vignesh M - 8 months ago 102
SQL Question

Random Number Generation in SQL Server

I Need to generate a random number between two numbers for each row.

For Eg:

select ColName,(Random nos between 1500 to 2000) from TableName

Thanks in advance

Answer Source
DECLARE @start INT
DECLARE @end INT

SET @start = 1500
SET @end = 2000

SELECT  Round(( ( @end - @start - 1 ) * Rand() + @start ), 0)

Update : To get random number for each row.

select ABS(Checksum(NewID()) % (@[email protected])) + @start
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download