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
 Other SQL Server Topics (2005)
 YEAR PART IN SQL 2005

Author  Topic 

baijuep
Starting Member

15 Posts

Posted - 2012-08-27 : 12:08:30
I HAVE A TABLE NAME ANIL AND A FIELD NAMED DOB (ie Date of Birth) datetime format. i want to query whose DOB is 2004 how can it be

baijuep

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-08-27 : 12:10:04
where DOB >= '01/01/2004' and DOB < '01/01/2005'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-27 : 17:47:42
generically

DECLARE @BirthYear int

SET @BirthYear=2004

SELECT * FROM ANIL WHERE DOB >= DATEADD(yy,@BirthYear-1900,0)
AND DOB < DATEADD(yy,@BirthYear-1899,0)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-27 : 17:48:30
logic is explained here

http://visakhm.blogspot.com/2012/07/generate-datetime-values-from-integers.html



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -