Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Update query syntax

Posted on 2008-10-20
17
Medium Priority
?
467 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 3
  • 2
  • +1
17 Comments
 
LVL 143

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

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

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 800 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 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22757434
do you have primary keys on the table(s)?
which columns?
0
 
LVL 1

Author Comment

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

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 800 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

715 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