Solved

Update query syntax

Posted on 2008-10-20
17
446 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 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 1

Author Comment

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

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

830 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