Discussion:
Help with INSERTing from a SELECT
(too old to reply)
John Cosmas
2005-06-30 04:13:52 UTC
Permalink
I have a SELECT statement that I run, which returns a set of records/rows.
After I run the first SELECT, I need to take those results and put it into
another TABLE. However, I don't want to use an INTO TABLE because the
destination table may be in use. I used SCATTER MEMVAR, but it only handles
the first record. Please let me know if there is a workaround to this.
Here is my original code.

SELECT * FROM car_stat ;
WHERE car_stat.K4 = m.pstrSearchK4 AND car_stat.a = m.pstrSearchA ;
PLAIN NOWAIT
SCATTER MEMVAR
USE wrk_car_stat SHARED AGAIN
INSERT INTO wrk_car_stat FROM MEMVAR
USE
Eric den Doop
2005-06-30 10:25:41 UTC
Permalink
INSERT INTO wrk_car_stat ;
SELECT * FROM car_stat ;
WHERE car_stat.K4 = m.pstrSearchK4 AND car_stat.a = m.pstrSearchA
--
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8
Post by John Cosmas
I have a SELECT statement that I run, which returns a set of records/rows.
After I run the first SELECT, I need to take those results and put it into
another TABLE. However, I don't want to use an INTO TABLE because the
destination table may be in use. I used SCATTER MEMVAR, but it only
handles the first record. Please let me know if there is a workaround to
this. Here is my original code.
SELECT * FROM car_stat ;
WHERE car_stat.K4 = m.pstrSearchK4 AND car_stat.a = m.pstrSearchA ;
PLAIN NOWAIT
SCATTER MEMVAR
USE wrk_car_stat SHARED AGAIN
INSERT INTO wrk_car_stat FROM MEMVAR
USE
Jeroen van Kalken
2005-06-30 10:34:56 UTC
Permalink
On Wed, 29 Jun 2005 23:13:52 -0500, "John Cosmas"
Post by John Cosmas
I have a SELECT statement that I run, which returns a set of records/rows.
After I run the first SELECT, I need to take those results and put it into
another TABLE. However, I don't want to use an INTO TABLE because the
destination table may be in use. I used SCATTER MEMVAR, but it only handles
the first record. Please let me know if there is a workaround to this.
Here is my original code.
USE wrk_car_stat SHARED AGAIN && moved !
SELECT * FROM car_stat ;
WHERE car_stat.K4 = m.pstrSearchK4 AND car_stat.a = m.pstrSearchA ;
PLAIN NOWAIT
SCAN
Post by John Cosmas
SCATTER MEMVAR
INSERT INTO wrk_car_stat FROM MEMVAR
ENDSCAN
Post by John Cosmas
USE
Or rewrite it to make it easier to understand (and faster)

SELECT * FROM car_stat ;
WHERE car_stat.K4 = m.pstrSearchK4 AND car_stat.a = m.pstrSearchA ;
INTO CURSOR myresult NOFILTER
SELECT 0
USE wrk_car_stat SHARED AGAIN
APPEND FROM DBF('myresult')

USE IN wrk_car_stat
USE IN myresult


TIP's:
Always give SELECT-results a cursor name, don't rely on it to result
in the cursor 'QUERY'.
Try to minimize the use of memory-variables, if possible use cursors.
SCATTER might overwrite a variable you didn't realize was also a table
field.
Kurt Grassl
2005-06-30 11:29:41 UTC
Permalink
Hi,
Post by Jeroen van Kalken
Always give SELECT-results a cursor name, don't rely on it to result
in the cursor 'QUERY'.
Try to minimize the use of memory-variables, if possible use cursors.
SCATTER might overwrite a variable you didn't realize was also a table
field.
... or use SCATTER NAME lo...

Kurt
John Cosmas
2005-06-30 15:07:49 UTC
Permalink
OK. So now that I have the table populated, I need to refresh the grid
whose recordsource is the wrk_car_stat. I ran the
ThisForm.gridCarStat.Refresh, but the data does not seem to appear in it.
Should I have some other settings in there as well?
Post by Jeroen van Kalken
On Wed, 29 Jun 2005 23:13:52 -0500, "John Cosmas"
Post by John Cosmas
I have a SELECT statement that I run, which returns a set of records/rows.
After I run the first SELECT, I need to take those results and put it into
another TABLE. However, I don't want to use an INTO TABLE because the
destination table may be in use. I used SCATTER MEMVAR, but it only handles
the first record. Please let me know if there is a workaround to this.
Here is my original code.
USE wrk_car_stat SHARED AGAIN && moved !
SELECT * FROM car_stat ;
WHERE car_stat.K4 = m.pstrSearchK4 AND car_stat.a = m.pstrSearchA ;
PLAIN NOWAIT
SCAN
Post by John Cosmas
SCATTER MEMVAR
INSERT INTO wrk_car_stat FROM MEMVAR
ENDSCAN
Post by John Cosmas
USE
Or rewrite it to make it easier to understand (and faster)
SELECT * FROM car_stat ;
WHERE car_stat.K4 = m.pstrSearchK4 AND car_stat.a = m.pstrSearchA ;
INTO CURSOR myresult NOFILTER
SELECT 0
USE wrk_car_stat SHARED AGAIN
APPEND FROM DBF('myresult')
USE IN wrk_car_stat
USE IN myresult
Always give SELECT-results a cursor name, don't rely on it to result
in the cursor 'QUERY'.
Try to minimize the use of memory-variables, if possible use cursors.
SCATTER might overwrite a variable you didn't realize was also a table
field.
Loading...