clarification in query

  • Hi All,

    Pls explain me the below query

    select * from xyz

    where year(created_on) <2010

    if i give date instead of year it will work?

    note: "xyz" is a table and "created_on " is column in my db

    Pls advice me

    very urgent.

  • Where are you going to "give a date"?

    Do you mean instead of 2010?

    That will not work, as YEAR(myColumn) returns an integer, so it needs another integer to be compared with, otherwise you get incompatible data type issues.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Thanks Keon Verbeeck

    now i understood.

    really thanks

  • The TSQL example below work since you are comparing apples with apples.

    select * from xyz where year(created_on) < year('2012-01-01')

    -- or

    select * from xyz where created_on < '2012-01-01'

    John Miner
    Crafty DBA
    www.craftydba.com

  • faroz2003 (3/16/2012)


    Hi All,

    Pls explain me the below query

    select * from xyz

    where year(created_on) <2010

    if i give date instead of year it will work?

    note: "xyz" is a table and "created_on " is column in my db

    Pls advice me

    very urgent.

    What is the datatype of "Create_on"?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply