Created
February 10, 2016 01:49
-
-
Save anonymous/112bc2108fce15788fc9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
@id = CA.Id, | |
@Ed = CA.EffectiveDate, | |
@sid = CA.SequenceId, | |
@cid = CA.CustomerId, | |
@ano = CA.AccountNo | |
FROM | |
( | |
-- Per Id | |
SELECT DISTINCT Id | |
FROM dbo.TestTable | |
) AS TT | |
CROSS APPLY | |
( | |
-- Single row with the highest EffectiveDate then SequenceId | |
SELECT TOP (1) TT2.* | |
FROM dbo.TestTable AS TT2 | |
WHERE TT2.Id = TT.Id | |
ORDER BY TT2.EffectiveDate DESC, TT2.SequenceId DESC | |
) AS CA; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment