how to select only 2nd record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ddtpmyra
    Contributor
    • Jun 2008
    • 333

    how to select only 2nd record

    I dont have my syntax now but here what I wanted to do...

    I have multiple rows under field name DateNote
    10/10/2010
    10/11/2010
    10/12/2010

    obviously when i get the minimun date it will give me the earliest which is 10/10/2010. Now what i wanted is after teh get the most earliest I wanted to catch the 2nd date after 10/10/2010 which is 10/11/2010.

    Please help
  • gpl
    New Member
    • Jul 2007
    • 152

    #2
    Try getting the minimum date that is larger than the real minimum date

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32668

      #3
      For a more general solution to the nth record, use the TOP predicate of n, then select the MAX() (or MIN() depending on sort order) of the returned result. IE use the TOP within a subquery.

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        What do you have so far?

        ~~ CK

        Comment

        • ddtpmyra
          Contributor
          • Jun 2008
          • 333

          #5
          I use outer apply and it works for me thanks for the help!

          Code:
          OUTER APPLY  
              (SELECT TOP 1  um.modifieddate as FirstRespDate, um.TaskNoteTypeId
               FROM dbo.TaskNote um (NOLOCK) 
                       where um.TaskNoteTypeId=2 and um.woid = t.WOID
                       and um.modifieddate is not null
                       order by um.ModifiedDate) as mbg

          Comment

          Working...