Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question sql server 2005. need help with query statement

    how can this statement be change from a MySql query to sql server 2005 query?

    SELECT
    DISTINCT
    TagID,
    x,
    y
    from RTLOC
    where TDate =
    (SELECT max(my.TDate) from RTLOC as my
    and TagID = my.TagID)



    i have 4 fields, TagID, x,y,Tdate.
    tag1, 123,523, date
    tag1, 123, 123, latest date
    tag2, 434,423, latest date
    tag2, 123,432, date
    tag3,342, 543,date
    tag3,532,342,latest date

    in the TagID field i have different names. i want to use a query statement to draw the x and Y of each different TagID by the latest TDate.

    expected result should be TagID , x , y , TDate
    tag1 ,123 ,123 ,latest date
    tag2 ,434 ,423 ,latest date
    tag3 ,532, 342 , latest date
    Last edited by xwarrior; 12-06-2006 at 02:56 AM.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    You were almost there, the AND in the subquery and the lack of alias for the first RTLOC were wrong.

    Here is a query that works:
    Code:
    SELECT DISTINCT TagID, x, y
    FROM RTLOC rt1
    WHERE (Tdate =
      (SELECT     MAX(rt2.TDate)
      FROM RTLOC rt2
      WHERE rt1.TagID = rt2.TagID)
    )
    I am the luckiest man in the world


  •  

    Posting Permissions

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