select pp.ownerid, pp.fsl_tableCode, m.mfr_id, pp.linkid parent_skuId, parentGTIN, childGTIN, cp.linkid child_skuId, h.childQty from tbl_GS1_ItemHierarchy h with (nolock) inner join tblManufacturers m with (nolock) on h.gln = m.gs1_gln inner join tbl_PRD_Packaging pp with (nolock) on parentGTIN = pp.scc14 and pp.linkType = 'SKU' and pp.ownerid = m.mfr_id inner join tbl_PRD_Packaging cp with (nolock) on childGTIN = cp.scc14 and cp.linkType = 'SKU' and cp.ownerid = m.mfr_id where nullif(gln,'') is not null order by GLN, parentGTIN insert into tbl_PRD_Hierarchy(ownerType, ownerId, catalogLevel, outerCatalogId, innerCatalogId, innerQty) values (, , , , , )