auto execute stored procedure

Posted on 2007-07-19
Last Modified: 2012-06-27
I have stored procedure that takes a from and to date parameters.

I want to execute the stored procedure in automatic loop - incrementing the To date by 1 until the specified end date is reached

For example:

EXEC dbo.spUpdateTran '01/01/2004',01/02/2004
End date = 12/31/2004

Once the first exec is complete then would automatically exceute
EXEC dbo.spUpdateTran '01/01/2004',01/03/2004  .. and so on until end date 12/31/2004 is reached

how would I do this?

Question by:krisred
    1 Comment
    LVL 35

    Accepted Solution


    something like this:

    declare @toDate datetime
    declare @fromDate datetime
    set @fromDate = getdate()
    set @toDate = '2007-08-01'

    while @fromDate < @toDate begin
      select @fromDate
      set @fromDate = dateadd( day, 1, @fromDate )


    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    In this article—a derivative of my blog post (—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
    Introduced in Microsoft SQL Server 2005, the Copy Database Wizard ( is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now