Thursday, April 3, 2014

SQl Query Help.


Yes Sorry , this is also one scenario can come in my data that is why.


please help,



I think, you did not answer Visakh's question still :) What would be your final result?


If you want to get the latest records with 'Approved' status, you can use the below(I assume that your case, but not sure.):



;With CTE
AS
(
SELECT *,
ROW_NUMBER() OVER (PARTITION BY ID ORDER BY [Date]) AS Rn
FROM Table
)Select * From CTE where Rn=1 and status='Approved'


No comments:

Post a Comment