This is a discussion on Duplicate a row in SP code within the SQL Server forums, part of the Microsoft SQL Server category; --> I'm sure there's a simple way to do it, I just haven't run into it yet: I just want ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| The solution depends on exactly what you mean by 'duplicate'. Hopefully, the following will get you started: CREATE TABLE MyTable1 ( Col1 INT NOT NULL CONSTRAINT PK_MyTable1 PRIMARY KEY ) CREATE TABLE MyTable2 ( Col1 INT NOT NULL CONSTRAINT PK_MyTable2 PRIMARY KEY ) INSERT INTO MyTable1 VALUES(1) INSERT INTO MyTable1 VALUES(2) GO CREATE PROCEDURE CopyRow @Col1 int AS INSERT INTO MyTable2 SELECT Col1 FROM MyTable1 WHERE Col1 = @Col1 GO EXEC CopyRow 1 -- Hope this helps. Dan Guzman SQL Server MVP "Lauren Quantrell" <laurenquantrell@hotmail.com> wrote in message news:47e5bd72.0402180610.60f76e50@posting.google.c om... > I'm sure there's a simple way to do it, I just haven't run into it yet: > I just want to duplicate a table record (row) using a stored procedure. > lq |
| |||
| What do you mean by "duplicate a row"? Normally we aim to avoid duplicating data in a database but here are two examples taken from Pubs. Iinsert a duplicate of a row into a table: INSERT INTO Authors (au_id, au_lname, au_fname, phone, address, city, state, zip, contract, total_sales, ytd_sales) SELECT <new PK value>, au_lname, au_fname, phone, address, city, state, zip, contract, total_sales, ytd_sales FROM Authors WHERE au_id = '172-32-1176' Return duplicates of a single row: SELECT au_id, au_lname, au_fname, phone, address, city, state, zip, contract, total_sales, ytd_sales FROM Authors CROSS JOIN (SELECT 1 UNION ALL SELECT 1) AS T(x) WHERE au_id = '172-32-1176' Neither of these examples serves much of a useful purpose but HTH. -- David Portas SQL Server MVP -- |
| ||||
| You can use the INSERT COMMAND for two times to get the duplicate records in your table, but be sure that there is no unique contrauint on that table. Regards Prashant Thakwani laurenquantrell@hotmail.com (Lauren Quantrell) wrote in message news:<47e5bd72.0402180610.60f76e50@posting.google. com>... > I'm sure there's a simple way to do it, I just haven't run into it yet: > I just want to duplicate a table record (row) using a stored procedure. > lq |
| Thread Tools | |
| Display Modes | |
|
|