May 16, 2011 at 11:58 am
Please check out the article in my signature and provide us some DDL and sample data. That makes our help that much easier to provide to you for free. 😀
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgMay 16, 2011 at 12:03 pm
Try this:
; WIHT CTE AS
(
SELECT RN = ROW_NUMBER() OVER ( PARTITION BY ReferenceNo , CODE ORDER BY Date DESC )
, *
FROM CTE
)
SELECT * FROM CTE WHERE RN = 1
May 16, 2011 at 3:12 pm
You didn't mention how big your table was (number of rows.)
To see some performance comparisons of different techniques dealing with a similar problem.
http://www.sqlservercentral.com/articles/T-SQL/69481/
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
Viewing 3 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply