Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using an sql statement as a condition in another action
Message
From
31/03/2000 18:56:41
 
 
To
31/03/2000 18:20:58
Michael Dougherty
Progressive Business Publications
Malvern, Pennsylvania, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00353571
Message ID:
00353721
Views:
13
>>UPDATE MyTable SET Field3 = .T. WHERE NOT Field2 IN (SELECT Field2 FROM MyTable WHERE Field3)
>
>This works in theory only:
>
>suppose that every record field3 = .F.
>..the subquery will yield no results, and the update will set every field3=.T.
>
>Considering that MyTable is likely to start with field3 being unassigned and the records being added with possible dupes on field2, it is likely this statement will be toggling the field3 values.
>
>The update sql is a great way to do this job, but like an SQL-Select, it takes a bit of tweaking before you get the correct results.

Michael,
the subquery will be reexecuted for each record in a table and only in case the value of Field2 absent in the subquery result, the Field3 will be changed.

Here is the small update (but, anyway, previous solution also works):

UPDATE MyTable SET Field3 = .T. WHERE Field2 NOT IN (SELECT Field2 FROM MyTable WHERE Field3)

Alex
Alex
Previous
Reply
Map
View

Click here to load this message in the networking platform