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)
 How to select last month of every year?

Author  Topic 

imblogger
Starting Member

2 Posts

Posted - 2008-07-07 : 03:42:36
Hi
I want to select only last month from 2004 to 2006
and from 2007 to 2008 all the months
can u help me out

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-07 : 03:55:33
didnt get that? do you mean you need to filter out records whose datefield staisfies the above condition?
Go to Top of Page

imblogger
Starting Member

2 Posts

Posted - 2008-07-07 : 03:59:05
yes
i have date column which have date from 2002 onwords
i want to select 2004 2005 2006 with only December
and from 2007 to 2008 all months
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2008-07-07 : 04:08:03
Guaranteed not to use any index that you may have, but will do as you want.

SELECT SomeColumns FROM someTable WHERE (year(SomeDate) IN (2004,2005,2006) AND Month(SomeDate) = 12) OR (year(SomeDate)>=2007)


Does that do what you want?

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -