Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
UPDATE not working
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01342335
Message ID:
01342392
Views:
23
>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
>
>
>
Thanks a lot for the explanation.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform