Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a new empty table from existing 2

Status
Not open for further replies.

button71

Programmer
Nov 8, 2006
69
AU
In my app I am sitting in an Area - say 5 with a table TEMP1 open. I need an empty copy of that table.

I have previously created a structure table TEMPER from TEMP1.

I want to CREATE TEMP2 FROM temper whilst leaving the original table open in Area 5.

When I run the create it replaces TEMP1 with TEMP2 in Area 5 and I can't seem to reopen TEMP1 in another Area.

Any suggestions?

Thanks

William
 
One method would be to use an SQL Query with parameters which ensured that there would be no records found.

Example:
Code:
USE SrcDBF IN 0
mcResult = "C:\Temp\NewDBF.dbf"
* --- If there were no Fld1 values < -9999 ---
SELECT *;
  FROM SrcDBF;
  WHERE Fld1 < -9999;
  NOCONSOLE;
  INTO TABLE (mcResult)
This will create the new table and leave it open in a different workspace.

OR use the COPY TO command.
Example:
Code:
USE SrcDBF IN 0
mcResult = "C:\Temp\NewDBF.dbf"
* --- If there were no Fld1 values < -9999 ---
SELECT SrcDBF
COPY TO (mcResult) FOR Fld1 < -9999
USE (mcResult) IN 0 ALIAS NewDBF
SELECT NewDBF
The COPY TO command will not leave the new table in USE, but you can then open it into the next available workspace (IN 0) and use it.

Good Luck,
JRB-Bldr
 
Hi William,

SELECT TEMP1
COPY STRUCTURE TO TEMP2

This will leave TEMP1 open and still selected.


Jim
 
jrbbldr, simply make it WHERE .F. or FOR .F., no need to make something up like Field<-9999.

Copy Structure is of course the simples, it compares to COPY TO with a FOR .F. Clause.

AFIELDS() would be a third way to do it. You can manipulate the intermediate array of fields, wipe out default values or trigger calls you may not want or the tablecopy, turn an autoinc field to a normal integer or reset the next autoinc value, etc. etc.

The command to create the table from that arrayis CREATE TABLE ...FROM ARRAY.

Bye, Olaf.
 
First, stop thinking about work area numbers. You never need to know them. You can always address work areas based on the alias of the table that's open there.

For your current problem:

SELECT 0 && moves to an empty work area
CREATE Temp2 FROM Temper

To return to Temp1:

SELECT Temp1

Now that I've said all that, I have to tell you that I haven't used COPY STRUCTURE or CREATE FROM in years. What are you actually trying to do?

Tamar
 
Thanks to everyone but Tamar's solution was the one that I was trying to work out.

I am using a table owned by another app. I do work on it and put the appropriate records into TEMP2 until the user decides to use TEMp2 as Temp1.

I know about SQL but it's not appropriate in this instance. I use it in many other areas of the program

Thanks

William
 
William,

Let me see if I have you - you have a table called Temp2 and the user can "decide" to use temp2 !!??

How can the user make this decision?

In a typical app, a user may have a temporary table (for example a data input batch might be stored in a temporary table when the user needs to close down the app and leave the batch open.) The data in that temporary table would be copied to the database in some sort of update. Even if the user wished to keep a number of batches open, you would only need one temporary table (you would use a batch identifier field.) Why would you need two temporary tables? (You would be better off giving the table a more descriptive table name than "temp1/temp2.")

OK assuming that you have this temporary table and you wish to give the user a clear table to work on. If the user chooses to update the data, use a command button and in your UpdateMethod() simply APPEND FROM Temp1 into your database table and then ZAP temp1. If the user chooses not to update the temp table, ZAP IN SELECT([Temp1]) and your table is clear and ready for new data.

There is no need to create a new Temp2 or Temp3 or what ever.


 
Ken

The TEMP table names are fictitious....I have real table names - one is an empty copy of the other that I can load with a selection of records form the first and manipulate without changing the first.

The user doesn't get near these tables only my app.

Anyway - the app is now working correctly as I have coded it.


Thank you

William
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top