Solved

Automatically Run Stored Procedure and Pass It the Current Date

Posted on 2008-10-29
5
418 Views
Last Modified: 2010-08-05
I just finished a stored procedure that needs to run automatically.  I wrote it so that I could pass it one parameter- a date.  How can I pass the current date to it from the scheduler without hard coding the date into the procedure?

The idea is that it'll run on the date needed but if I want to test it I can pass it any date I want.

Any ideas?  this is running on MS SQL 2005.

thanks!
0
Comment
Question by:digitalwav
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 22834149
put this call in a sql agent job...schedule to run whenever you want.

declare @date datetime
set @date = GETDATe()

exec yourprocname @dateparam = @date
0
 
LVL 4

Expert Comment

by:nasserd
ID: 22834152
You can use T-SQL within the stored proc to retrieve the execution date: GETDATE()
0
 
LVL 1

Author Comment

by:digitalwav
ID: 22834193
chapmandew- perfect- didn't know I could do all that in the command window.  How can I quickly format it as yyyy-mm-dd ?
0
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 22834222
declare @date varchar(20)
set @date = convert(varchar(20), getdate(), 111)
exec yourprocname @dateparam = @date
0
 
LVL 1

Author Closing Comment

by:digitalwav
ID: 31511327
Thanks! Works perfectly!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 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