Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Passing in a parameter

Author  Topic 

andros30
Yak Posting Veteran

80 Posts

Posted - 2008-09-25 : 12:24:06
I'm trying to automate a job and I need to pass in a date parameter. What is the best way?

Situation: On the 25th of each month I need to run a stored procedure and pass in the first day of next month.
Example: dbo.usp_Statements_UpdateStatementSendFlag '10/01/08'. Currently I'm running this manually and putting in the date myself.

I got this to give me the date but I'm having difficulty trying to apply this into the procedure.

select convert(varchar(10),dateadd(m,1,dbo.udf_FirstDayOfMonth(getdate())),101)

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-25 : 12:29:33
select DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0)

this will start of next month on any day
Go to Top of Page

andros30
Yak Posting Veteran

80 Posts

Posted - 2008-09-25 : 13:03:11
quote:
Originally posted by visakh16

select DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0)

this will start of next month on any day



That does simplify it. Now I need to incorporate that into my procedure like:

dbo.usp_Statements_UpdateStatementSendFlag 'DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0)'

Is this possible?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-25 : 13:13:48
quote:
Originally posted by andros30

quote:
Originally posted by visakh16

select DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0)

this will start of next month on any day



That does simplify it. Now I need to incorporate that into my procedure like:

dbo.usp_Statements_UpdateStatementSendFlag 'DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0)'

Is this possible?


DECLARE @MonthStart datetime
SELECT @MonthStart=DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0)

dbo.usp_Statements_UpdateStatementSendFlag @MonthStart
Go to Top of Page

andros30
Yak Posting Veteran

80 Posts

Posted - 2008-09-25 : 13:27:30
quote:
Originally posted by visakh16

quote:
Originally posted by andros30

quote:
Originally posted by visakh16

select DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0)

this will start of next month on any day



That does simplify it. Now I need to incorporate that into my procedure like:

dbo.usp_Statements_UpdateStatementSendFlag 'DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0)'

Is this possible?


DECLARE @MonthStart datetime
SELECT @MonthStart=DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0)

dbo.usp_Statements_UpdateStatementSendFlag @MonthStart




That does the trick... Thank you so much for helping.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-25 : 13:28:27
you're welcome
Go to Top of Page
   

- Advertisement -