× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



For a file with columns KEY1, DTA1, DTA2

INSERT INTO mytable
SELECT 'NewKeyValue', DTA1, DTA2
WHERE KEY1 = 'OrigKeyValue'

You will not be able to use * to select your fields.

Eric

-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx]On Behalf Of Pete Helgren
Sent: Tuesday, May 13, 2008 2:16 PM
To: Midrange Systems Technical Discussion
Subject: Copying a record using SQL and updating the key


Is there a way to copy an existing record using SQL except for the key?
There is something way back in the recesses of my mind that says yes,
but I haven't been able to come up with syntax that works.

A statement like "Insert into myfile (select * from myfile where key =
1) " should copy a record with key = 1 and insert it. But in a uniquely
keyed file, it would cause a duplicate key error. Can I create a new
record with a new key value without identifying all the existing
fields? If my first field is the key, having to do something like
"insert into myfile (select
'2',field2,field3,field4,field5,field6....field50 from myfile where key
= 1) would create a valid new record with a key of '2' but is a hassle
to code all the field references when there are a bunch of them (50 in
this example).

Any tricks here or do I need to include all the fields in the select
statement individually in order to create a "copy" and insert it with a
new key value.

Thanks

Pete Helgren




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.