Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to write a Transact SQL Statement to get three different numbers that are unique in the database rounded upto three digits. How do i do this?
Posted
Comments
Santhosh Kumar Jayaraman 27-Sep-12 6:43am    
give some examples or output for your scenario

1 solution

Hi,

See the below link. It might be help you to find your solution.

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

See the Method :1
SQL
DECLARE @Random INT;
DECLARE @Upper INT;
DECLARE @Lower INT

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


Viprat
 
Share this answer
 
v2
Comments
Maciej Los 28-Sep-12 13:29pm    
Good work, my 5!
Interesting link ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900