johnson1
asked on
duplicate rows
Hello,
I have a table that creates a tree. It is like this:
Id(int), ParentId(int)
101, 0
105, 101
190, 101
195, 190
I want to duplicate the items so the result should be something like this:
201, 0
205, 201
290, 201
295, 290
How is best to do this'
I have a table that creates a tree. It is like this:
Id(int), ParentId(int)
101, 0
105, 101
190, 101
195, 190
I want to duplicate the items so the result should be something like this:
201, 0
205, 201
290, 201
295, 290
How is best to do this'
ASKER
The Id is identity column, so I do not know the id number until after I have inserted the row.
johnson1,
Do you want:
a. In Query?
b. As a new Table? or
c. In the same table?
(see my first post)
It is not clear what you are asking for. Could you please explain a bit?
Mike
Do you want:
a. In Query?
b. As a new Table? or
c. In the same table?
(see my first post)
It is not clear what you are asking for. Could you please explain a bit?
Mike
ASKER
Hello,
I am doing this in a query. I already have a table with thousands of rows. I want to duplicate the rows, but each new row will get new Id because Id is an identity column. And the ParentId has to point to the new id.
In the real table I have also a column that groups toghether the rows. I added below the column GroupId.
Id(int), ParentId(int), GroupId(int)
101, 0, 10
105, 101, 10
190, 101, 10
195, 190, 10
121, 0, 11
125, 121, 11
127, 121, 11
139, 127, 11
I would like to copy the rows that have certain GroupId. For example GroupId=10.
I want to insert the rows into the same table and create a new groupId.
Please let me know if this is not clear.
I am doing this in a query. I already have a table with thousands of rows. I want to duplicate the rows, but each new row will get new Id because Id is an identity column. And the ParentId has to point to the new id.
In the real table I have also a column that groups toghether the rows. I added below the column GroupId.
Id(int), ParentId(int), GroupId(int)
101, 0, 10
105, 101, 10
190, 101, 10
195, 190, 10
121, 0, 11
125, 121, 11
127, 121, 11
139, 127, 11
I would like to copy the rows that have certain GroupId. For example GroupId=10.
I want to insert the rows into the same table and create a new groupId.
Please let me know if this is not clear.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
As a new Table:
Open in new window
In the same table:
Open in new window
Provided id is uneatable.