Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 441
  • Last Modified:

Automatically Run Stored Procedure and Pass It the Current Date

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
digitalwav
Asked:
digitalwav
  • 2
  • 2
1 Solution
 
chapmandewCommented:
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
 
nasserdCommented:
You can use T-SQL within the stored proc to retrieve the execution date: GETDATE()
0
 
digitalwavIT Infrastructure ManagerAuthor Commented:
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
 
chapmandewCommented:
declare @date varchar(20)
set @date = convert(varchar(20), getdate(), 111)
exec yourprocname @dateparam = @date
0
 
digitalwavIT Infrastructure ManagerAuthor Commented:
Thanks! Works perfectly!
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now