Reputation: 36476
I'm trying to call a stored procedure with a varchar
containing the name of the previous month.
exec my_sp @subject='Report for June 2011';
Except June 2011
should be dynamic (dependent upon the month you call the stored procedure), not static. What's the best way to accomplish this?
I can get the previous month in the desired format like so:
select datename(month, dateadd(month,-1,getdate()))+' '+datename(year, dateadd(month,-1,getdate()))
but I don't know how to pass it to the stored procedure.
Upvotes: 1
Views: 584
Reputation: 6205
DECLARE @ReportMonth VARCHAR(100)
SELECT @ReportMonth = 'Report for ' + DATENAME(MONTH, DATEADD(MONTH,-1,GETDATE()))+' '+DATENAME(YEAR, DATEADD(MONTH,-1,GETDATE()))
EXEC my_sp @subject=@ReportMonth
Upvotes: 1
Reputation: 31630
Declare @reportText varchar(40);
Set @reportText = datename(month, dateadd(month,-1,getdate()))+' '+datename(year, dateadd(month,-1,getdate()))
exec my_sp @reportText;
Upvotes: 1