Using waitforto set delay

  • Hi,

    My requirement is to compare count of a table between a hour difference and if it remains same i do the next task.

    For exapmle, here in the below code i want the second select statement to run after 5 seconds.

    But when i run this snippet, it waits for 5 seconds and give both the result at the same time.

    select count(*) from table1

    waitfor delay '0:0:5'

    select count(*) from table2

    Please advice.

    Thanks

    Dev

  • if you run that in QA it would buffer up the results and return it to you in one go. if you are waiting an hour between checks output the count result to a holding table and compare to that. schedule a job to run once an hour.

    ---------------------------------------------------------------------

  • I can not create another table. Yes what i can do it that i can create a global temporary table, but our server reboot schedule is weekely, which will delete the table.

  • Dev (7/22/2008)


    I can not create another table.

    why not?

    ---------------------------------------------------------------------

  • Dev (7/22/2008)


    Hi,

    My requirement is to compare count of a table between a hour difference and if it remains same i do the next task.

    For exapmle, here in the below code i want the second select statement to run after 5 seconds.

    But when i run this snippet, it waits for 5 seconds and give both the result at the same time.

    select count(*) from table1

    waitfor delay '0:0:5'

    select count(*) from table2

    Please advice.

    Thanks

    Dev

    George has the right idea. If you run your code with a delay of 1 hour you will be holding a shared lock on table1 for an hour, probably causing some performance issues.

    You should have a job that runs your first step and stores the data and then an hour later have a job that runs the second step, comparing it to the first jobs results to determine whether or not you continue.

    If you cannot create a table then create the global temp table and just do an if (Object_Id(tempdb.dbo.##table) is null Create ##table end then you are recreating the table as needed. Your table should have 1 column and only 1 row which is the value from the last run. You should delete the value as part of job 2.

  • As per present business policy for the server.

  • Hmmm...

    I agree to George's idea, but the poblem is that i can not create table now.

    Global temp tables is only the next possible option i think.

    Thank you both for your quick suggestion.. 🙂

  • Dev (7/22/2008)


    As per present business policy for the server.

    I would hope you can get a one column one row table past this 'policy'

    ---------------------------------------------------------------------

  • I would try to 🙂

Viewing 9 posts - 1 through 8 (of 8 total)

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