Dear Friends,
Dear Friends,
I would like to write a stored prcedure which reads data from one
table and inserts into different table.
The data in one table is actually coming from Stored procedure, so the
data is dynamic and can have multiple parent child relation ships
within the same table. Below I am showing some sample data
id ==> identity column
id parent_id description
1 0 test1
2 1 test2
3 1 test3
4 2 test4
5 2 test5
6 3 test6
7 3 test7
8 5 test8
9 6 test9
10 9 test10
As you see above id is parent_id for some other record.
one id can have multiple children or it may not have any children like
id 1.
Now, I want to write a stored procedure based on the above relations
and copy the data exactly into new table maintaining same parent child
relation ships. But since id is the identity column when I insert the
record it comes up with new id, so I have to maintain the id and
associate that newly generated ID to the parent_id filed based on
above relations.
so from the above example data, I want to get the data like below.
id parent_id description
11 0 test1
12 11 test2
13 11 test3
14 12 test4
15 12 test5
16 13 test6
17 13 test7
18 15 test8
19 16 test9
20 19 test10
Your help would be greatly appreciated.
Thanks,
Kdsv
Any ideas/suggestions are really appreciated.
Thanks,
Kdsv
Roy Harvey (SQL Server MVP) - 08 Jul 2008 14:05 GMT
Have you considered using SET IDENTITY_INSERT ON? That would allow
copying the data without generating new identify values IF there are
no conflicts with values already in the target table.
Roy Harvey
Beacon Falls, CT
>Dear Friends,
>
[quoted text clipped - 55 lines]
>
>Kdsv