Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 select a random # between a range

Author  Topic 

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2007-05-09 : 16:41:47
Hi,

I need to select a random number between 999900000 and
1000897681.

When I use:

select round(rand() * 1000897681, 0)

I get a number from 0 to 1000897681, but I a random number from within a specified range.

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-05-09 : 16:54:03
You can use the function on the link below.

Random Integer, Sample, and Datetime Functions
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=69499


select [Random Integer] = [dbo].[F_RANDOM_INTEGER](999900000,1000897681,newid() )



CODO ERGO SUM
Go to Top of Page

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2007-05-09 : 16:56:52
Actually I just did this:

select round(rand() * 997681, 0) + 999900000

(997681 = upper bound - lower bound)
Go to Top of Page
   

- Advertisement -