Solved

Update query syntax

Posted on 2008-10-20
17
433 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 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

19 Experts available now in Live!

Get 1:1 Help Now