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

Updating tables with other tables 1

Status
Not open for further replies.

abbyanu

IS-IT--Management
Jan 18, 2001
82
US
Hi

I have two tabled, say A and B. I want to update table B by adding to it corresponding values (via the primary key) from Table A. If a record is present in both table A and B, I can successfully update it in B using the UPDATE command, but I'm having problems updating table B with a record in A that is not present in B. Could someone please advise me on how to go about this?

I want all the new records (present in A, but not in B) to be added to B as new records while the records(i.e. B=A) in A that have are related in B to be updated in B (say B=B+A).

Thanks for your time.

Abe.
 
I would do This :

SELECT A
DO WHILE NOT EOF()
SCATTER MEMVAR
SELECT B
SEEK A.Field && Primary key field
IF NOT FOUND()
APPEND BLANK
ENDIF
GATHER MEMVAR

SELECT A
SKIP
ENDDO

I hope this helps.
 
Just a note in the prevous code
Assuming that you want to do that within scope of records in the table A, SEEK you frist record and then use SCAN REST WHILE to loop within your scop. Second use SCATTER/GATHER MEMVAR MEMO if you have memo fields in you tables
Thanks Walid Magd
Engwam@Hotmail.com
 
thanks for the tips.

tried the first code, but alas, i ain't getting nothing'. will try incorporating Magd's (salaam aleikum ;)

any more info will be appreciated.

peace!

abe.
 
I am assuming that table B was already indexed. If not, that may be the problem. Also, between 'SELECT A' and 'DO WHILE NOT EOF()', you may want to say GO TOP to insure you are starting at the beginning of the table.

Good luck
 
I am sorry for all my friends, the next paragraph is just for Abbyanu and it is not in English,
Wa alykom el salam ya basha, makontish motawake3 atkalem 3arabi hana. Anyways, forsa sa3eeda gadan ya rayes
Salam Walid Magd
Engwam@Hotmail.com
 
dear spayne, dear walid...

the last tip resolved it... de ting's now kickin' like kudzu ;) many thanks for your time!

peace, abe.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top