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
 General SQL Server Forums
 New to SQL Server Programming
 More complex random example

Author  Topic 

landau66
Yak Posting Veteran

61 Posts

Posted - 2007-12-17 : 08:02:45
Hi all!
I have a table with three columns: Identity, DateTime (current_timestamp) and one which I want to fill with random values always depending on the value in the same column one row above.

Since I want it to be a stored procedure I have to pass three parameters - an initial value, the range within the random number is higher or lower than the number in the preceding row and the number of rows which should be inserted. This means that as soon as a new row is inserted there is also a new seed for the random value for the next line.

My problem now is that I would always get out the same number. Maybe you know a solution for my problem.

Many thanks and greetings from Austria

Landau

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-17 : 08:05:06
ABS(CHECKSUM(NEWID())) % MaxNumber



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-17 : 08:27:50
Also refer http://sqlblogcasts.com/blogs/madhivanan/archive/2007/10/10/generating-random-numbers-part-ii.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -