Good news we have Ranking Functions
in sql server to make these kind of operations very simple. Note it is only available in Sql Server 2005 and later editions.
select *,
ROW_NUMBER() OVER (PARTITION BY AccountID ORDER BY SomeColumn) SequenceNumber
from TSM310_PATIENT_NOTES PN