Question

I am importing data from one database to another. The hierarchyid column must also be ported over with the relationships intact.

If the target table is empty, it's easy. When the target contains rows, the hierarchy as it is in the source table will not be valid in the target table

The easiest would be to increment all values in the hierarchy field with the value of the first ported row's primary key.

So if a source row's hierarchyid was '/1/12/13/' and the next available id in target before importing was 101, the hierarchy should change so each value is incremented by 100: '/101/112/113/'

I have read Updating “Hierarchyid” in SQL Server, but do not see how it can be applied to my problem.

How would I go about incrementing each number in each hierarchyid of each row by 1 set value, i.e. increment all numbers in the hierarchy field by 100?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top