P.S. Do you have something in the Archive table that will allow you to sort in Chronological order?
We have two additional columns in our Archive Tables:
Action - whether it was an Update or a Delete (we don't store the inserted/current record in the Archive table)
Archive Data - the Date/Time that the row was Updated / Deleted
So in our reports we provide a "dummy" value for these two columns, for the Parent table, of "*" and the Update Date of the record (which is typically a few ms earlier than the archive record, which is created by an After Trigger)
We also have Create and Update Date/Time and User, in all tables, and also an Edit Number (incremented each time the row is updated, used for Optimistic record locking on web pages)
We store Archive Records for a period of time (based on data retention policy [for THAT table]), so it is possible that there are a lot of rows in the archive table, for a given PKey, so for our normal User Report we only show the most recent 100 rows.
Given that the Current Record may have an Update Date/Time that is slightly older than the latest row in the Archive Table we force the sort of the Current Record first (for a given PKey ID)
So our query for the Current and Archive records on a single, specific, PKey value looks like this:
SELECT Act -- Action = U)pdate, D)elete and "*" for Current Record
, ArchiveDate
, EditNo -- Edit Number / Record Version
, CreateDate
, CreateUser
, UpdateDate
, UpdateUser
, MyID
, MyCol1
, MyCol2
, ...
FROM
(
SELECT [Act] = '*'
, [ArchiveDate] = UpdateDate
, EditNo, CreateDate, CreateUser, UpdateDate, UpdateUser, MyID
, MyCol1, MyCol2, ...
FROM dbo.MyTable
WHERE MyID = @MyID
UNION ALL
SELECT *
FROM
(
SELECT TOP 100
Act, ArchiveDate -- Columns specific to Archive Table
, EditNo, CreateDate, CreateUser, UpdateDate, UpdateUser, MyID
, MyCol1, MyCol2, ...
FROM dbo.MyTableArchive
WHERE A_MyID = @MyID
ORDER BY ArchiveDate DESC
) AS X
) AS X
ORDER BY
-- X.MyID, -- Only required if multiple PKey rows included
CASE WHEN [Act] = '*' THEN 1 ELSE 2 END
, X.[ArchiveDate] DESC, EditNo DESC
This doesn't translate well to a VIEW because if it is necessary to restrict the ID on both the MainTable and the Archive Table, I suspect performance would be impaired (removing the TOP 100, and nesting of that sub-select) would probably solve that, if "all" archive records could be included, or perhaps using ROW_NUMBER ... OVER would perform well)