Create duplicate record based on existing one

They have: 5,633 posts

Joined: Jan 1970

Does anyone know how to create a duplicate recordset based on an existing one? I'm using SQL Server 2000 with an ASP front-end.

When I say recordset, I mean my complete record spans multiple tables and those values would need cloning too.

I imagine a user selecting an existing record, then clicking a button called CLONE ME and the following occurs:

1. The selected record is cloned (not just the main table, but related records in the other tables too)
2. The new cloned record is assigned a new unique ID (which is of course carried over to its related records in the other tables too)

Any thoughts on how to accomplish such a task? Thank you.

They have: 5,633 posts

Joined: Jan 1970

You could have something like the following:

INSERT INTO tablename (field1,field2,field3, etc) VALUES
((SELECT field1value FROM anothertable WHERE criteria = something),(SELECT field2value FROM yetanothertable WHERE criteria = something),etc,etc)

Just an idea
Bj

They have: 461 posts

Joined: Jul 2003

aside from bjmcg's sugestion, you could pull all the information from all the tables that correspond to the information fo the selection, then puts it into variables.

you then insert all the new information into new sets.

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.