[thelist] Random value between 1 and x with SQL Server 2K

Guy Babbitt Guy_Babbitt at FSAFOOD.COM
Sun Jul 29 13:04:45 CDT 2001


--What language are you using? This looks like a stored procedure to me, but
--what do I know. Are you using some other programming language to call the
--stored procedure? If so, why not generate the random seed with that, then
--pass it to the stored procedure?

You are correct, I need to do it in a stored procedure.  I need to entire
process to take place within the procedure (written in transact-sql) as I would
otherwise have to run a function to do a count on the select, then save that
value to a variable and pass it to a script outside to generate a random number
which would then be passed in to a second function to create a cursor and go
fetch that specific record.

There must be a way to pull this off within transact-sql, the code I included
before gave me back a random value, but does not appear to be truly random from
the testing I have done (ie with 5 possible records 3 and 4 come up a lot more
often than 1, 2, or 5).

Thanks again!

Guy Babbitt
Systems Architect






More information about the thelist mailing list