473,840 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with SELECT in UPDATE Statement

I need to update values in a table (where they are null or zero) with
values from another table for the corresponding PopulationMembe rID.

Now I now that you can't update where there is a join.. but the join
is in the nested select.. so it should work right?

CurrentDb.Execu te ("UPDATE Samples SET
samples.SampleM emberEmployees= (SELECT pop.PopMemberEm ployees FROM
population as pop WHERE [Pop].[PopulationMembe rID]=[samples].
[PopulationMembe rID]) WHERE nz(sampleMember Employees,0)=0 AND
SurveyID=" & CurrentSurvey)

when the query is executed i get: :"Operation must use an updatable
query. (Error 3073)"

I worked around this by creating a vba function accepting the Id as a
parameter.. but its slow..

Apr 20 '07 #1
1 4332
On Apr 20, 4:38 am, Mikle <mikl...@gmail. comwrote:
I need to update values in a table (where they are null or zero) with
values from another table for the corresponding PopulationMembe rID.

Now I now that you can't update where there is a join.. but the join
is in the nested select.. so it should work right?

CurrentDb.Execu te ("UPDATE Samples SET
samples.SampleM emberEmployees= (SELECT pop.PopMemberEm ployees FROM
population as pop WHERE [Pop].[PopulationMembe rID]=[samples].
[PopulationMembe rID]) WHERE nz(sampleMember Employees,0)=0 AND
SurveyID=" & CurrentSurvey)

when the query is executed i get: :"Operation must use an updatable
query. (Error 3073)"

I worked around this by creating a vba function accepting the Id as a
parameter.. but its slow..
Try something like this (it should be sufficiently fast):

dim db as dao.database, r as dao.recordset, q as dao.recordset, s as
string
set db=currentdb
q=db.createquer y("")
s="Select ...;"
set r=db.openrecord set(s, dbopensnapshot)
r.movefirst (Not really necessary)
do while not r.eof
s="Update Samples set SampleMembersEm ployees = " & r!
PopMemberEmploy ees _
& " WHERE ..." (fill in correct statement here)
q.sql = s
q.execute
r.movenext
loop
close r
set r=nothing
set q=nothing

This should be fairly fast and quite a bit quicker than using the VBA
function.

-- Larry Engles
Access developer since day 1 of Access 1.0


Apr 20 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4689
by: Nicolas Payre | last post by:
Hi, I have the following SQL that I want to use to update a table. It doesn't work ! Does someone knows why? ** I Know it could be done easy with a CURSOR FOR LOOP, but still... Thanks for your help. update XSORA1A.XS0011T_STATISTIQUES_UNIX a
4
2259
by: 001 | last post by:
Hello, The select statement needs only 1 second to complete the query. But the update statement spends 30 minutes. Why? SELECT STATEMENT: declare @IDate smalldatetime select @IDate=col001 from USDay select * from USDay A
2
19532
by: Ray | last post by:
I have a list of about 20,000 rows that I am updating. I loop through each row in my program and basically do the following (1) select * from TABLE where SID= for update /*lock the row*/ (2) Update TABLE set ACCESS_DATE=current date where SID= (3) Do not commit (4) Next row After each SID in the list is finished being updated I want to commit all the updates. If any update fails I want to rollback the entire
15
3630
by: Hemant Shah | last post by:
Folks, We have an SQL statement that was coded in an application many years ago (starting with DB V2 I think). When I upgraded to UDB 8.2, the optimizer does not use optimal path to access the data. It takes about 4 minutes to get the data. In previous versions it was instantaneous. What do I need to do to increase the performance?
4
1612
by: Mervin Williams | last post by:
I have several tables involved in my application, but the two in question here are the company and address tables. The company table has business_address_id and mailing_address_id columns, which are both foreign keys to the address table. So, the stored procedure to which my SelectCommand points to reads as: ALTER PROCEDURE dbo.CompanyInfoByCompanyID ( @companyid int
19
8388
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without FOR UPDATE, it is fine and no error. I also tried Set objRs = objConn.Execute("SELECT * FROM EMP UPDATE OF EMPNO"), but it still couldn't help. any ideas? I tried to search in the web but couldn't find similar
3
2199
by: shark | last post by:
Hi all. i am facing a deadlock problem .i have included the -t1204 and -T3605 trace flags and have got the following o/p pu tin sqls server logs. 2006-06-01 17:49:21.84 spid4 2006-06-01 17:49:21.84 spid4 Wait-for graph 2006-06-01 17:49:21.84 spid4 2006-06-01 17:49:21.84 spid4 ... 2006-06-01 17:49:26.92 spid4 ResType:LockOwner Stype:'OR' Mode: S
2
4982
by: mob1012 via DBMonster.com | last post by:
Hi All, I wrote last week about a trigger problem I was having. I want a trigger to produce a unique id to be used as a primary key for my table. I used the advice I received, but the trigger is still not working correctly. Here is my code: create trigger emp_update_id BEFORE update on emp_update REFERENCING NEW AS N for each row SET unique_id = Generate_unique();
0
1514
by: Gagan Sindhu Dewangan | last post by:
Below is the following procedure where I am facing the problem, the work of the below procedure is to update the database. query result:sp_helptext bProjectUpdate Text ...
2
2889
osward
by: osward | last post by:
Hello there, I am using phpnuke 8.0 to build my website, knowing little on php programing. I am assembling a module for my member which is basically cut and paste existing code section of various module that I found it useful. Here is the 1st problem I encounter: I had a function to edit a event row form the database which is fine with me, than I pass on the code to a function that save(update) the data to the database.
0
9861
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9699
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10301
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9444
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7023
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4078
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3139
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.