Solved

Automatically Run Stored Procedure and Pass It the Current Date

Posted on 2008-10-29
5
398 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
  • 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

803 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