Breaking News
Loading...
23/12/2013

SQL Server: Create random number

Here I create a random number from 100 to 999
DECLARE @Random INT;
DECLARE @Upper INT;
DECLARE @Lower INT

SET @Lower = 100 ---- The lowest random number
SET @Upper = 999 ---- The highest random number
SELECT @Random = ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0)
SELECT @Random 

http://blog.sqlauthority.com/2007/04/29/sql-server-random-number-generator-script-sql-query/

0 comments:

Post a Comment

 
Toggle Footer