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 2008 Forums
 Transact-SQL (2008)
 Get the rows based on given range of day and month

Author  Topic 

naveendkt
Starting Member

5 Posts

Posted - 2011-12-20 : 15:25:09
I have name and datetime field in the table called date of birth.
I want to get the name based on given date and Month range.


Technically,

"WHERE Date BETWEEN '20010101' AND '20120501'"

I don't want to compare the Year field in the above condition. So the result will have rows between 01/01 and 05/01 for all the year in the table.

Naveen

naveendkt
Starting Member

5 Posts

Posted - 2011-12-20 : 16:13:15
Hi guys,
I found the solution for this..

you can resolve by replacing year of date field by a fixed value (ex:2000):


where cast('2000-'+cast(month(date) as varchar(2))+'-'+cast(day(date) as varchar(2)) as date) between '01-01-2000' and '05-01-2000'


Thank You


Naveen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-12-21 : 03:01:35
or

where right(convert( varchar(8),date,112),4)*1 between 101 and 501

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -