?
Solved

auto execute stored procedure

Posted on 2007-07-19
1
Medium Priority
?
297 Views
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?

0
Comment
Question by:krisred
1 Comment
 
LVL 35

Accepted Solution

by:
David Todd earned 2000 total points
ID: 19526817
Hi,

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 )
end

HTH
  David
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

831 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