2013-01-08 83 views

回答

0

你沒有提到是否要生成獨特的非重複的隨機數。

DECLARE @Random INT; 
DECLARE @Upper INT; 
DECLARE @Lower INT; 

---- This will create a random number between 1 and 999 
SET @Lower = 1000 ---- The lowest random number 
SET @Upper = 9999 ---- The highest random number 
SELECT @Random = ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0) 
SELECT @Random; 

Source