Select *, row_number() Over(Partition by StudentID Order by EntryDate) From Students
DECLARE @students TABLE (student VARCHAR(20), attendDate DATETIME)INSERT @students SELECT 'student1','1/1/2008' UNION SELECT 'student1','2/1/2008' UNION SELECT 'student1','3/1/2008' UNION SELECT 'student2','2/1/2008' UNION SELECT 'student2','3/1/2008' UNION SELECT 'student2','4/1/2008' UNION SELECT 'student2','5/1/2008' UNION SELECT 'student3','3/1/2008' UNION SELECT 'student3','5/1/2008' SELECT (SELECT COUNT(*) FROM @students WHERE student = s.student AND attendDate < s.attendDate) + 1 AS row ,student ,attendDate FROM @students AS s