add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table tbl
(
ItemID int,
ParentID int,
TemplateID int
)
insert into tbl values
(1001, NULL, 86),
(1002, 86, 41),
(1003, 43, 44),
(1004, NULL, 43),
(1005, 44, 73);
5 rows affected
UPDATE t1
SET ParentID = t2.ItemID
FROM tbl t1
INNER JOIN tbl t2 ON t1.ParentID = t2.TemplateID
3 rows affected
SELECT *
FROM tbl
ItemID ParentID TemplateID
1001 null 86
1002 1001 41
1003 1004 44
1004 null 43
1005 1003 73