We help IT Professionals succeed at work.

auto execute stored procedure

krisred
krisred asked
on
Medium Priority
317 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?

Comment
Watch Question

Senior Database Administrator
CERTIFIED EXPERT
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.