April 11, 2007 at 7:18 am
Hi i'd like t create a variable to hold the current month -1.
So far i have this where i hard code the month into it. i'd like not to hard code the month into the code.
Declare @month varchar(15)
set @month = 'March'
select @month
Result = march
The result am looking for would be to select all the data from my table were month = month -1 i would use a @month variable in the select statement.
For example i would get all the data in the table for march if i run the query today..or up untill the 30th of April and then on the 1st of may i get all the data for April
April 11, 2007 at 7:27 am
Try this:
declare @month varchar(15)
set @month = datename(mm,dateadd(mm,-1,getdate()))
select @month -- to see what you got
April 11, 2007 at 7:39 am
Hi Lynn,
Thanks i get the variable @month as 'march' which is the result am looking for thank you
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply