Solved

Automatically Run Stored Procedure and Pass It the Current Date

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

20 Experts available now in Live!

Get 1:1 Help Now