Time randomization ideas

  • 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!! 


    Thank you!!,

    Angelindiego

  • 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.

  • Well, I will start playing now...Thank you so much for the input!


    Thank you!!,

    Angelindiego

  • 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.

  • Thanks David, with a couple of tweaks, this one worked!!!!


    Thank you!!,

    Angelindiego

  • 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.

  • Thanks Ryan....I will keep this for another time!!


    Thank you!!,

    Angelindiego

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply