VERY URGENT...How to find employee having experience>250 months

  • VERY URGENT...How to find employee having experience>250 months

  • You might find that you try members' patience if you repeatedly post the same question three times.  If you post it in the correct place just once, we will still see it.

    We need much more information than you're giving, as well.  Post the table structure, some sample data and what you expect the result set to be and somebody will be able to help.

    John

  • Using sysdate() function get the difference in the month

    select * from employee where

    datediff(month,sysdate(),person_starting_date)>250

  • Private message from original poster:

    Table structure  is like this..

    empId,Name,Address,Salary,Hire Date,Department

    Sample data:

    001,Lenin,bangalore,30000,12 Sep 2004,HR

    I think Avinash means to use getdate() instead of sysdate()...  Also, if your table is large then you can put it like this to make it more likely that any index you have on the [Hire Date] column will be used by the query optimiser:

    select [Name] from YourTable

    where [Hire Date] < dateadd (month, -250, getdate())

    John

  • You may also use this:

    Select * from TableName

    Where datediff(month,HireDate,getdate())>250

    Note: HireDate is the column name.

    It should return same result.

  • Yes, but it will not utilize any indexes. John's query will.


    N 56°04'39.16"
    E 12°55'05.25"

  • I always wait on "Very Urgent" requests like this that have such a simple basis... it usually means that someone is taking an SQL test as part of an interview and, frankly, if they can't answer such simple questions, they don't deserve the job.... so, I wait...

    --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 7 posts - 1 through 7 (of 7 total)

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