Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
UPDATE not working
Message
 
 
To
27/08/2008 16:24:35
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01342335
Message ID:
01342389
Views:
19
Any table in the FROM clause can be a source of update. There're different ways to write such UPDATE. I prefer the one I used because I can write SELECT (query) first to see what records will be updated. After that I can copy FROM clause from SELECT into UPDATE statement.
CREATE CURSOR TableToUpdate (PK I, txt C(20))
INSERT INTO TableToUpdate VALUES (1, "One")
INSERT INTO TableToUpdate VALUES (2, "Two")
INSERT INTO TableToUpdate VALUES (3, "Three")
CREATE CURSOR Updates (PK I, txt C(20))
INSERT INTO Updates VALUES (1, "1")
INSERT INTO Updates VALUES (3, "3")

* #1
* Test select to see wich records will be updated
SELECT * ;
	FROM TableToUpdate  JOIN Updates ON TableToUpdate.pk = Updates.pk
* UPDATE itself
UPDATE TableToUpdate SET txt = Updates.txt ;
	FROM TableToUpdate  JOIN Updates ON TableToUpdate.pk = Updates.pk

* #2 - The same as #1 but using table aliases
SELECT * ;
	FROM TableToUpdate ttu JOIN Updates upd ON ttu.pk = upd.pk
UPDATE ttu SET txt = upd.txt ;
	FROM TableToUpdate ttu JOIN Updates upd ON ttu.pk = upd.pk

* #3 - Old style JOIN using WHERE clause. 
* A table alias cannot be used for table that has been updated.
UPDATE TableToUpdate SET txt = Updates.txt ;
	FROM Updates WHERE TableToUpdate.pk = Updates.pk
>Ok. Why is the FROM referencing the covr table? Logically it seems like it would be the patient table as that is where the update is coming from. Just trying to understand the logic of it.
>
>>It replaces with date in the current record in the 'patient' table because you did not specify any relations between 2 tables.
>>
>>update covr set ph_dob = patient.ptdob ;
>>	FROM covr JOIN patient ON covr.pat_no == patient.ptpn
>>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform