Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to: append selected records to a table
Message
From
13/11/2002 09:04:09
Patrick O'Neil
American Specialty Information Services
Roanoke, Indiana, United States
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
How to: append selected records to a table
Miscellaneous
Thread ID:
00722066
Message ID:
00722066
Views:
52
hello all --

say i have 2 tables (with the same structure of course) called
X_USER and X_GENERIC. say they have a unique (PK) field called
"code".

at some point, X_USER has copies of some of the records that are
(still) in X_GENERIC. (after i copied records into X_USER, i
modified them, and don't want to lose my changes).

how (hopefully in a single statement, without using a bunch of
temporary tables) can i get the records from X_GENERIC, that are
not already in X_USER (determined by PK) and add them to X_USER,
without overwriting X_USER.

i looked into APPEND FROM, but the FOR clause doesn't allow
SQL style WHERE condition. (see below)

i looked into SELECT-SQL, but it overwrites the entire table.

here is my most recent attempt, which does not add any records,
even tho new records are in X_GENERIC.
  SELECT 0
  USE (X_GENERIC_Table_Spec) ALIAS X_GENERIC SHARED
  
  SELECT 0
  USE (X_USER_Table_Spec) ALIAS X_USER
  

  SELECT X_GENERIC.code     AS code     , ;
         X_GENERIC.describe AS describe , ;
         X_GENERIC.replace  AS replace    ;
INTO DBF X_USER                           ;
    FROM X_GENERIC                        ;
   WHERE X_GENERIC.code NOT IN            ;
            (SELECT X_USER.code FROM X_USER)

  Number_Added = _TALLY
  
  =MESSAGEBOX ( STR(Number_Added) , 0 , 'Number added' )

  SELECT X_GENERIC
  USE

  SELECT X_USER
  USE
regarding the APPEND approach... since i couldn't specify a
SQL-style where clause, i have used a UDF in the FOR clause,
which worked ok, but that seems kind of clumsy. i'm looking
for something a little more elegant (and more efficient).

thanks for any help.
patrick
Next
Reply
Map
View

Click here to load this message in the networking platform