Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL equivalent for APPEND FROM
Message
 
To
23/08/2001 11:45:12
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00548045
Message ID:
00548255
Views:
10
Randy,

An approach we had to apply in similar case is the following...
All via SQL statements using SQLExec( nHandle, cStatement ) to the given server.

select * from customer where 1=2

this will bring back an empty structure to a local cursor.

select * from customer_history where 1=2

this will bring back an empty structure to another local cursor.

Now, dimension appropriate arrays and
afields( laCustomer, "local_customer_cursor" )
afields( laHistory, "local_history_cursor" )

Then you will have the structures of each table locally..
With a for loop, scan through each field in the customer table that ALSO exists in the history and build a string of these fields that match. Build a string on the common fields
lcFields = ""
for lnI = 1 to alen( laCustomer, 1 )
   if ascan( laHistory, laCustomer[lnI,1] ) > 0
     */ we have a match...
     */ Ex: Last_Name, First_Name, Address, etc...
     lcFields = lcFields + iif( empty( lcFields ), "", ", " );
              + laCustomer[lnI,1]
   endif
endfor
Issue some other call to extract the customer records to a holding table that meet your conditions to move to history...

select * into (sql-side table) from customer where last_order_date more than 3 years (or whatever condition)...

Then you'll have to come up with a mechanism to assign/build the unique IDs on the temp table appropriately,

then you can finish "appending" back to the existing history table with

now, build a string for SQLExec

lcSQLAppend = "insert into customer_history ";
+ "( " + lcFields + " ) values ";
+ "(select " + lcFields + " from temp_customer_table)"

The Insert from a Select statement is almost exactly like an append. You have to qualify each field in same sequence that match both tables as we built the string with. However, you caution on fields that REQUIRE values in history that may not exist on customer source... if so, allow null, or force some other bogus value as needed.

Hope this helps, or at least opens your eyes to a possible alternative.

Don
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform