• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

not sure how to select certain years from the query? using MSSQL 2008 express

how? thanks
select * from myData Where FORMAT(myData.Date,'yyyy') <='2004'
1 Solution
Pratima PharandeCommented:
select * from myData Where year(myData.Date) <=2004
2004 will not be enough. You need it to be before the 1st of January.
And since you including 2004, then it is january 2005

select * from myData Where year(myData.Date) <'20050101'

Open in new window

Asim NazirCommented:
For details on Year see here: http://msdn.microsoft.com/en-us/library/ms186313.aspx
You may also use DATEPART function like DATEPART(year, '12:11:28.123')
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

SharathData EngineerCommented:
try this/
select * from myData Where datepart(year,[Date]) <='2004'

Open in new window

or this
select * from myData Where [Date] <='01/01/2004'

Open in new window

goodkAuthor Commented:
goodkAuthor Commented:
thanks Sharath

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now