Solved

Update query syntax

Posted on 2008-10-20
17
440 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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
 
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 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

810 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