Solved

Automatically Run Stored Procedure and Pass It the Current Date

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

932 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

9 Experts available now in Live!

Get 1:1 Help Now