Solved

Update query syntax

Posted on 2008-10-20
17
421 Views
Last Modified: 2012-06-22
Found examples on EE, and built my own update query, but cant figure why it wont work.

Updateing table "tblStock" from a select query "qry StkInDetails Grouped"


**ACCESS 2007
UPDATE ts 

SET ts.pc = tn.pcs

FROM tblStock AS ts 
 

INNER JOIN 

[qry StkInDetails Grouped] AS tn 

ON (ts.pkg = tn.pkgs) 

AND (ts.PartNo = tn.PartNo) 

AND (ts.Brand = tn.Brand) 

AND (ts.Category = tn.Category) 

AND (ts.Location = tn.Location)

WHERE (((ts.pkg)=0))

Open in new window

0
Comment
Question by:CMDAI
  • 10
  • 3
  • 2
  • +1
17 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22757139
please try this small modif:
UPDATE ts 
SET ts.pc = tn.pcs
FROM tblStock AS ts 
INNER JOIN [qry StkInDetails Grouped] AS tn 
ON ((ts.pkg = tn.pkgs) 
AND (ts.PartNo = tn.PartNo) 
AND (ts.Brand = tn.Brand) 
AND (ts.Category = tn.Category) 
AND (ts.Location = tn.Location))
WHERE (ts.pkg=0)

Open in new window

0
 
LVL 1

Author Comment

by:CMDAI
ID: 22757207
i get the same error
pic.jpg
0
 
LVL 1

Author Comment

by:CMDAI
ID: 22757217
access highlights the work FROM
0
 
LVL 1

Author Comment

by:CMDAI
ID: 22757228
access highlights the word FROM
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 22757242
sorry, in ms access the syntax is indeed a bit different than ms sql server:
UPDATE tblStock AS ts 

INNER JOIN [qry StkInDetails Grouped] AS tn 

ON ((ts.pkg = tn.pkgs) 

AND (ts.PartNo = tn.PartNo) 

AND (ts.Brand = tn.Brand) 

AND (ts.Category = tn.Category) 

AND (ts.Location = tn.Location)) 

SET ts.pc = tn.pcs

WHERE (ts.pkg=0)

Open in new window

0
 
LVL 1

Author Comment

by:CMDAI
ID: 22757292
ACCESS : Operation Must be an updatable Query.
0
 
LVL 1

Author Comment

by:CMDAI
ID: 22757303
I cannot update table from Query? :(
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22757434
do you have primary keys on the table(s)?
which columns?
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 1

Author Comment

by:CMDAI
ID: 22757459
"tblStock" has 'ID'
but
"qry StkInDetails Grouped" doesnt have , its a Union, Select Query
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 22757490
how many tables were used in [qry StkInDetails Grouped] ?
3 or more?

does the query uses aggregate functions i.e., sum,average, etc ?
0
 
LVL 1

Author Comment

by:CMDAI
ID: 22757503
The table and the query
pic2.jpg
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 200 total points
ID: 22757506
0
 
LVL 1

Author Comment

by:CMDAI
ID: 22757530
I nee to get back home, will get back here in about 15 min

0
 
LVL 11

Expert Comment

by:bmatumbura
ID: 22758085
Try the following code... you can't use an alias as the table being updated:
UPDATE tblStock 

SET pc = tn.pcs

FROM tblStock AS ts 

INNER JOIN [qry StkInDetails Grouped] AS tn 

ON ((ts.pkg = tn.pkgs) 

AND (ts.PartNo = tn.PartNo) 

AND (ts.Brand = tn.Brand) 

AND (ts.Category = tn.Category) 

AND (ts.Location = tn.Location))

WHERE (ts.pkg=0)

Open in new window

0
 
LVL 11

Expert Comment

by:bmatumbura
ID: 22758254
You may have to include the WHERE part in the INNER JOIN like so:
UPDATE tblStock 

SET pc = tn.pcs

FROM tblStock AS ts 

INNER JOIN [qry StkInDetails Grouped] AS tn 

ON ((ts.pkg = tn.pkgs) 

AND (ts.PartNo = tn.PartNo) 

AND (ts.Brand = tn.Brand) 

AND (ts.Category = tn.Category) 

AND (ts.Location = tn.Location)

AND (ts.pkg = 0))

Open in new window

0
 
LVL 1

Author Comment

by:CMDAI
ID: 22758698
OK thank's this code worked, and i worked around
The Union, with VB (create , Update , Delete Table)
UPDATE tblStock AS ts 

INNER JOIN [qry StkInDetails Grouped] AS tn 

ON ((ts.pkg = tn.pkgs) 

AND (ts.PartNo = tn.PartNo) 

AND (ts.Brand = tn.Brand) 

AND (ts.Category = tn.Category) 

AND (ts.Location = tn.Location)) 

SET ts.pc = tn.pcs

WHERE (ts.pkg=0)

Open in new window

0
 
LVL 1

Author Closing Comment

by:CMDAI
ID: 31507798
Thank's again
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now