Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2010
    Posts
    3

    Unanswered: Tricky select stmt - help

    PHP Code:
    Hi 

    I have the following data in one of the table 
    'TestTab' 

    code,     finished_dtm,     end_dtm 
    =============================== 
    ABC    (null)        (null
    ABC    2009-08-10    2009-08-10 
    ABC    2009
    -08-01    2009-08-09 
    XYZ    2008
    -02-04    2008-02-04     

    How to write a select satement to 
    return values when 

    if finished_dtm is null then return that record 
    else 
      return 
    max(end_daterecord 

    thank you 

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Code:
    SELECT TOP 1 *
    FROM MyTable
    ORDER BY COALESCE(finished_dtm, '20790606') DESC

    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    i'm betting that left unsaid in the original post was the phrase "for each code"

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Well, my codings are working excelent for the question that was said

    But I will not bet against you...
    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
  •