update a
set principalid =b.principalid 
from tablename a,tablename b
where a.areaid=b.areaid
and b.principalid is not null
and a.name<>b.name