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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert-select

Status
Not open for further replies.

iansr

Programmer
Aug 31, 2001
11
PH
Greetings!
How do i do an insert-select in vfp?

AS in (Sql server):

INSERT INTO foo (ID)
SELECT ID FROM bah

thanks in advance!
 
Sorry,

Unfortunatly that syntax doesn't work if FoxPro. You have to do it in 2 steps, select the data you want and then insert it into the table. I included a couple of examples, but there are many other ways of doing it.

Hope this helps,
Bo Durban


SELECT ID FROM bah INTO CURSOR curTemp
SELECT foo
APPEND FROM (DBF("curTemp"))
USE IN "curTemp"

-or-

SELECT ID FROM bah INTO CURSOR curTemp
SELECT curTemp
SCAN
SCATTER MEMO NAME oTemp
SELECT foo
APPEND BLANK
GATHER MEMO NAME oTemp
ENDSCAN
USE IN "curTemp"
 
thanks BoDurban,

what i actually want to do is return a random record.
I plan to create a cursor with a randNum column that's just an auto-increment column and the ID column containing the key of the row i want to return. that's why i needed the insert select, but i'll try your advice, thanks! And is there another approach to return a random row?


this might be a stupid question but how do i call stored procedures? I refrained from using them and instead defined all code in programs because i didn't know how to call em.

also, is there a good reference site about visual foxpro? MSDN is not really helpful.
 
Hi

You can do the insert and repace functions in a single command...
INSERT INTO myDBF FROM MEMVAR

The above code inserts a record into the table myTable from the MEMVAR previously populated. The idea is that the TABLE activity will be fast. Memory manipulations dont hold other users wheras the INSERT into TABLE holds others as well as the erplace etc functions. If this is done in one act, you could surely feel better.

Hope this helps :)
ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
LET KNOW IF THIS HELPED. ENOUGH EXPERTS ARE HERE TO HELP YOU OUT! BEST OF LUCK :)
 
It worked! i also got something similar to run. thanks alot! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top