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 2005 Forums
 Transact-SQL (2005)
 datetime field question

Author  Topic 

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2009-08-31 : 13:28:56
I need to search the datetime field to find is a specific year is equal to the year provided by the user??

Dave
Helixpoint Web Development
http://www.helixpoint.com

cat_jesus
Aged Yak Warrior

547 Posts

Posted - 2009-08-31 : 13:38:56
Select * from sometable
where year(datecolumn) = '2009'

An infinite universe is the ultimate cartesian product.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-01 : 03:16:06
or if you want to make use of index (if defined)

declare @year int
set @year =2009

Select * from sometable
where datecolumn >= DATEADD(YEAR,@year-1900,0) and datecolumn < DATEADD(YEAR,@year-1900+1,0)




Madhivanan

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

- Advertisement -