Re: duplicating a record in SPL
Posted in 1996
Toby Denbow (tdenbow@mathworks.com) wrote:
>Subject: duplicating a record in SPL
>From: tdenbow@mathworks.com (Toby Denbow)
>Date: Mon, 25 Mar 1996 16:22:39 -0500
>Message-ID: <tdenbow-2503961622390001@tdenbow.mathworks.com>
>
>Say I have a table called tab1 with three columns in it, called col1,
>col2, col3.
>
>col1 is a serial column that does not allow dups,
>col2 is int, and col3 is int
>
>How can I duplicate a record so it gets teh next serial number for col1,
>but simply duplicates the values for col2, and col3? The only column
name
>that I want to hardcode is the serial column.
>
>For example:
>record1 looks like:
>col1 = 100
>col2 = 2
>col3 = 3
>
>I want to duplicate record1 and create a new record that looks like:
>col1 = 101
>col2 = 2
>col3 = 3
>
>
>insert into tab1 values (select * from tab1 where col1 = 100);>will not work because I would duplicate the serial number.
How about either of these two, depending upon your own stylistic
preference for explicitly using SERIAL values of zero, or omitting
on insert.
1) INSERT INTO tab1 (col2, col3)
VALUES (SELECT col2, col3 FROM tab1 WHERE col1 = 100);
2) INSERT INTO tab1
VALUES (SELECT 0, col2, col3 FROM tab1 WHERE col1 = 100);
Paul Kapp ----> PLKapp@aol.com -OR- plk@interactive.visa.com