+ Reply to Thread
Results 1 to 3 of 3

Thread: Insert using values and subselect

  1. Default Insert using values and subselect

    Lets say the file is call yourfile and is in library yourlib The file contails 4 fields, field1 field2 field3 field4 where field 2 is the key field then the SQL would be something like insert into yourlib/yourfile a select b.field1, '1234', b.field2, b.field3, b.field4 from yourlib/yourfile b where.......; then you insert whatever you want in the ......

  2. #2
    Guest.Visitor Guest

    Default Insert using values and subselect

    I need to insert records from one database to the same database and would like to use SQL --- effectively copying a record and changing the key. The round about way that I use is to create record set fetch the records into a data structure, change key to the structure, and update the key on the insert using values. I thought that there may be a more efficient way of doing so with a single statement. Is this possible?

  3. #3
    garylavery@aol.com Guest

    Default Insert using values and subselect

    You can do what "padshore" says. But be careful not to create a dupe key or the statement fails. Even with a "WHERE" clause, your incoming data can have it's own duplicate. The "WHERE" clause will not access the records just inserted - only the records that existed prior to the start of the statement. And it's not easy to find the dupe key since it's not explicitly noted in any error message. I do literally hundreds of thousands of inserts every week and the only way I could create bulletproof code was by creating the records in a non-keyed temp file first, deleting dupes in that (slow!), THEN going from the temp file to the master file with the "WHERE" clause in place. Hope this helps.

+ Reply to Thread

Similar Threads

  1. SQL Subselect: Soup to Nuts
    By T.Grove in forum SQL
    Replies: 10
    Last Post: 11-30-2007, 05:34 AM
  2. SQL Delete with subselect
    By Guest.Visitor in forum SQL
    Replies: 3
    Last Post: 11-04-2004, 06:57 AM
  3. INSERT INTO - Must I specify all fields?
    By dchristie in forum SQL
    Replies: 3
    Last Post: 10-29-2004, 06:34 AM
  4. Using INSERT into
    By ramm@mvmills.com in forum Programming
    Replies: 2
    Last Post: 05-25-2001, 06:02 AM
  5. INSERT error
    By Guest.Visitor in forum Programming
    Replies: 8
    Last Post: 06-20-2000, 01:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts