create trigger T_update on yourtable for insert
as
select top 1 identity(int,1,1) as idd,* into #t from inserted order by idd desc
update #t set caption=parentid+nodeid from #t where nodeid is not null
update #t set caption=parentid+nodeid from #t where nodeid is null
drop #t
go