Here is another T-SQL syntax you can use:
(By the way, I agree with cletus about denormalization issues.)
-- create dummy table create table test (id int, name varchar(20), parentid int, parentname varchar(20)) go -- add some rows insert test values (1, 'parent A', null, null) insert test values (2, 'parent B', null, null) insert test values (3, 'parent C', null, null) insert test values (11, 'child A 1', 1, null) insert test values (12, 'child A 2', 1, null) insert test values (33, 'child C 1', 3, null) go -- perform update update c set parentname = p.name from test c join test p on c.parentid = p.id go -- check result select * from test
source share