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

Posted on 2011-04-25
Last Modified: 2012-05-11
how? thanks
select * from myData Where FORMAT(myData.Date,'yyyy') <='2004'
Question by:goodk
    LVL 39

    Expert Comment

    by:Pratima Pharande
    select * from myData Where year(myData.Date) <=2004
    LVL 4

    Expert Comment

    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

    LVL 10

    Expert Comment

    by:Asim Nazir
    For details on Year see here:
    You may also use DATEPART function like DATEPART(year, '12:11:28.123')
    LVL 40

    Accepted Solution

    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


    Author Comment


    Author Closing Comment

    thanks Sharath

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
    If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now