I build a tree (material style) and transform some data. Consider the following table:
BillOfMaterials
Now I use CTE to populate it:
with BOM as
(
select @@identity as BomId, null as ParentId <some other fields> from MyTable
union all
select @@identity as BomId,
parent.BomId as ParentId,
some other fields
from MyTable2
inner join BOM parent on blabla)
insert into MyTable3
select * from BOM
The problem is that the identifier @@ will only give me the identifier of the last record inserted before the join.
What can I do to get a personality? I can change table 3 but not table1 or table2
row_number() has undefined behavior for a recursive query, so I cannot use it here.
I know I can use a GUID, is this the only option?
source
share