It would be much easier if you had a "verbal" definition of First Record. What is the exact definition of a group?
Is it (code1, year)? Can you add an IDENTITY column to the table?
SELECT *
FROM table1
WHERE identcol = (
SELECT TOP identcol
FROM table1 t
WHERE t.code1 = table1.code1
AND t.year = table1.year
ORDER BY code2)
Or something like that <s>
-Mike