Print Page | Close Window

Duplicate a record / many records

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=5119
Printed Date: 30 March 2026 at 7:50pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Duplicate a record / many records
Posted By: pedalcars
Subject: Duplicate a record / many records
Date Posted: 19 August 2003 at 5:42am
I want to duplicate records within a table; e.g., find all records where (for example) "Type = 1" and add new records containing the same information in all the other fields but with a new "Type" (say, 9).

I can do a SELECT table.* WHERE table.type = 1

then run through until EOF doing:

strOtherField = rs("OtherField")
(etc for all fields)


then do another rs, adding a new record each time such as,

rs2.Fields("type") = 9
rs2.Fields("OtherField") = strOtherField
(etc for all fields)

rs2.Update

rs.MoveNext
Loop


However, that seems a bit intensive - is there a "Duplicate" command, or some other neater way of doing this?

-------------
http://www.pedalcars.info/ - www.pedalcars.info

The most fun on four wheels




Replies:
Posted By: ljamal
Date Posted: 19 August 2003 at 6:02am
you can insert information from a table that has been selected from a table using the insert statement
insert into table (fieldname, fieldname2, fieldname3, ... type) select (fieldname, fieldname2, fieldname3, ... 9) from table where type=1

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: MorningZ
Date Posted: 19 August 2003 at 10:42am

and just a note:

that's absolutely horrid database design/schema to deep copy almost an entire record...

You're better off having one table of "Type"-s and another with the info and then have a table in between tying together the info rows and the mulitple type rows...... 

my 2 cents anyways



-------------
Contribute to the working anarchy we fondly call the Internet



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net