AOB
Registered User.
- Local time
- Today, 05:55
- Joined
- Sep 26, 2012
- Messages
- 615
Hi there,
I have a query which I use to populate a recordset (effectively, a subset of a table based on some criteria), which is then looped through and updated (can't avoid the loop - I can't update the table with SQL, it requires VBA code unfortunately)
Stupidly, I forgot that if the query to populate the recordset uses outer joins, the recordset becomes inherently non-updatable. So the loop errors out. :banghead:
Here is/was the original query - the joins are used purely as a criteria for inclusion for the records in the main table which need to be updated; no records in the joined tables should be edited.
In order to make the recordset editable, I have to remove the joins like this :
But this makes the query a lot slower.
Just wondering if anybody has any suggestions for a better way to do this?
Cheers!
AOB
I have a query which I use to populate a recordset (effectively, a subset of a table based on some criteria), which is then looped through and updated (can't avoid the loop - I can't update the table with SQL, it requires VBA code unfortunately)
Stupidly, I forgot that if the query to populate the recordset uses outer joins, the recordset becomes inherently non-updatable. So the loop errors out. :banghead:
Here is/was the original query - the joins are used purely as a criteria for inclusion for the records in the main table which need to be updated; no records in the joined tables should be edited.
Code:
SELECT A.field1, A.field2
FROM (tbl1 A
LEFT JOIN tbl2 B ON A.field3= B.field3)
LEFT JOIN tbl3 C ON A.field3= C.field3
WHERE B.field3 Is Not Null
OR C.field3 Is Not Null
OR A.checkflag = True
Code:
SELECT A.field1, A.field2
FROM (tbl1 A
WHERE A.field3 IN (SELECT B.field3 FROM tbl2 B)
OR A.field3 IN (SELECT C.field3 FROM tbl3 C)
OR A.checkflag = True
Just wondering if anybody has any suggestions for a better way to do this?
Cheers!
AOB