Results 1 to 3 of 3

Thread: SQL Query help

  1. #1
    Join Date
    Mar 2010
    Posts
    1

    Unanswered: SQL Query help

    Hello.

    Can anyone help with this problem.

    I have a table, which looks like this:

    ID DATE_FROM STAT NUMBER
    ---------------------------------------
    100 1.12.2009 20 1
    200 10.12.2009 20 1
    100 10.12.2009 25 2
    100 15.12.2009 20 3
    200 15.12.2009 25 2

    Table contains data for statuses of an ID. It has a valid from date and numer is a following number of a state for one id. If you want to get the latest status of one ID, you just pick the last number.
    But I need to get number of IDs, who had a status 25 on a date 11.12.2009.
    In this case the result must be:

    ID DATE_FROM STAT NUMBER
    ---------------------------------------
    100 10.12.2009 25 2

    Thank you

    Best regards,
    Levi

  2. #2
    Join Date
    Feb 2007
    Location
    Chennai, TN
    Posts
    68

    SQL Query help

    Are you looking for something like below,

    Select top 1 * from table
    where DATE_FROM <= '11.12.2009'
    and STAT = 25
    order by DATE_FROM desc

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Code:
    SELECT ID, DATE_FROM, STAT, NUMBER 
    FROM table
    WHERE DATE_FROM <= '20091211'
    AND STAT = 25
    Using ISO date format will prevent SQL Server making a nonsense of 12th November and 11th December.
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •