How to run tsql query every 15 minutes

  • Hi Gurus

    I need to write a query which can run every 15 minutes till count(*) in the table becomes 0(zero).

    declare @Records INT

    set @Records = select count(*) from Mytable

    where duration < 100

    duration will be updated continuously. I want to make sure every row in the table has duration = 100

    and I want to run sql query every 15 minutes in a loop till that happens. Every 15 minutes I want to print time and total number of records on the screen

    Is it possible by using only Sql query ??

    Thanks in Advance.

    Mayur

  • are you not able to use a job for this?

  • Or... you could kick off the proc and do a WAITFOR DELAY 'hh:mm:ss'.

    Of course, if the server get's taken down or the job ever fails, you need to manually restart it.

    Suggestion of creating a "job" for it is probably the best.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I want to make sure every row in the table has duration = 100

    I would consider a trigger to catch any attempt to save duration <> 100 in the table.

    What to do when it's happened - it's up to you.

    Either report it immediately or store a record in another table which will be inspected on regular basis.

    _____________
    Code for TallyGenerator

  • Better opt out for a job and schedule to run every 15 mins

    Cheers,
    Sugeshkumar Rajendran
    SQL Server MVP
    http://sugeshkr.blogspot.com

  • Hi,

    The best and most flawless solutions is to make a job. 🙂

    Regards

    Take Care

    Avaneesh.

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

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