views:

13

answers:

1

Let's say I have the following table

fID Field1  Field2
1   a       dennis
1   f       mac 
2   j       clownbaby
1   k       charlie
3   t       frank
7   d       dee

and I want to take all the rows with 1 in the first column and insert them in the same table with a number I could pick as an argument to my stored procedure. So that if I called my stored procedure as rowClone(1,8) I would end up with a table with

fID Field1  Field2
1   a       dennis
1   f       mac 
2   j       clownbaby
1   k       charlie
3   t       frank
7   d       dee
8   a       dennis
8   f       mac
8   k       charlie
+1  A: 
Create Procedure RowClone(@fIDToClone int, @newFID int)
As
Insert Table(fID, Field1, Field2)
Select @newFID, Field1, Field2
From Table
Where fID = @fIDToClone

You will probably want to add an additional check that ensures that the routine does not create duplicates. However, you did not mention what unique keys exist on the table.

Thomas