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 2000 Forums
 Transact-SQL (2000)
 Last Month

Author  Topic 

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2003-12-01 : 06:01:04
I'm trying to do something that I suspect has been done before so hopefully someone will have some tips. I'm trying to extract all the events from the previous month to when the extract is run.

My table is
EventID , EventDate,...

What I want is everything where the EventDate is between the 1st of the previous month and the last of the previous month. So if I ran it today (1st December) it would give 1st Nov to 30th Nov. If I ran it yesterday (30th Nov) it would give 1st Oct to 31st Oct.

Does anyone have anything like this or any clues?

What I had in mind was some quite complex stuff that takes the first of the previous month and the first of the current month but it seems very cumbersome.

thanks

steve

Steve no function beer well without

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2003-12-01 : 06:19:57
select * from t where

datepart(mm,EventDate)=datepart(mm,dateadd(mm,-1,getdate()))
and
datepart(yy,EventDate)=datepart(yy,dateadd(mm,-1,getdate()))
Go to Top of Page

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2003-12-01 : 06:40:28
That's much simpler than what I had in mind

thanks

steve

Steve no function beer well without
Go to Top of Page
   

- Advertisement -