Checking for a date that is within the prior month that I am running

I am running a report and I would like to check DATEA  is within the prior month that I am running?

Example:   If I run the report on October 9, I would like to select all records that DATEA is in September.

What would the syntax be in an MSSQL query using getdate() as today's date?
moriniaAdvanced Analytics AnalystAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
to get the start of this month:
select convert(datetime, convert(varchar(8), getdate(), 120) + '01', 120)

so:

select * from yourtable
 where DATEA <=  convert(datetime, convert(varchar(8), getdate(), 120) + '01', 120)
   and DATEA > dateadd(month, -1,  convert(datetime, convert(varchar(8), getdate(), 120) + '01', 120))

see also:
http://www.experts-exchange.com/A_1499.html
 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.