I have the code shown below that is part of my where clause. I need to get all data for the previous calendar month, so July 1 - 31 right now since we're in August. This statement is giving me all July data, but includes multiple years in it. How can I fix that?
where datepart(m, BEG_DATE) = datepart(m, dateadd(m, -1, getDate()))
and datepart(y, BEG_DATE) = datepart(y, dateadd(m, -1, getDate()))