SQLTeam.com | Weblogs | Forums

How to Order by

How do I order by c.id in the Outer apply

   OUTER APPLY (SELECT c.recordid, 
                     dbo.GROUP_CONCAT_D(c.Comment, ' ')
                     AS Comment 
              FROM   tbltrkcomment c 
                     JOIN tbltrkcommenttype t 
                       ON c.commenttypeid = t.id 
              WHERE  t.NAME LIKE 'Description' and  t1.id = c.recordid

-- Is it possible to ..... Order by c.id
GROUP BY c.recordid) t68

You can't add an ORDER BY in the OUTER APPLY (except with TOP (n)) because it's meaningless. You need to add the ORDER BY to the main SELECT that contains the OA.