May 4, 2006 at 11:52 am
I have some scripts that pull data from tables for an auto population each night. I am looking for an idea of how to randomize the times going into the db. I have randomizations for the values, but all of the times are the same. I need some variance. Any ideas oh wise friends of mine??????????? Thanks a ton!!
May 4, 2006 at 12:03 pm
You might try experimenting with something like:
CONVERT(DATETIME, RAND() * XXXX)
Though that's probably not a very good way to get random sampling. For some reason this seems to work okay:
SELECT CONVERT(DATETIME, RAND() * 36500)
Someone with more expertise in random value generation is probably going to cruise in here and correct me though.
May 4, 2006 at 12:08 pm
May 4, 2006 at 12:10 pm
SELECT
Result = Dateadd(dd,Round(((Rand() - .5) * 100),0),Getdate())
will deliver a random date somewhere between 50 days in the past and 50 in the future.
May 4, 2006 at 7:21 pm
May 5, 2006 at 4:05 am
Hi all,
I see you have a solution, so this is just FYI. You can use newid() to generate random numbers/dates for each row in a table...
select dateadd(ms, cast(cast(newid() as binary(4)) as int), getdate()), name from master.dbo.sysobjects
Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
May 5, 2006 at 8:48 am
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply