SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 YEAR PART IN SQL 2005
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

baijuep
Starting Member

India
15 Posts

Posted - 08/27/2012 :  12:08:30  Show Profile  Reply with Quote
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

USA
37470 Posts

Posted - 08/27/2012 :  12:10:04  Show Profile  Visit tkizer's Homepage  Reply with Quote
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

India
52325 Posts

Posted - 08/27/2012 :  17:47:42  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 08/27/2012 :  17:48:30  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.14 seconds. Powered By: Snitz Forums 2000