Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MS access and Update/Select

Posted on 2016-11-02
5
Medium Priority
?
192 Views
Last Modified: 2016-11-03
How can I do something like below in MS access, where I'm updating a record in the  equipment table based on a related record in th e same equipment table.  

update equipment set local_indicator_id = (select local_id from equipment where id = 8309)  
where equipment.id = 8265
0
Comment
Question by:HLRosenberger
5 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 1000 total points
ID: 41871067
try
update equipment set local_indicator_id = (select local_id from equipment As E where E.id = 8309)  
 where equipment.id = 8265
0
 
LVL 40

Accepted Solution

by:
PatHartman earned 1000 total points
ID: 41871114
Open the QBE.
Add the equipment table twice.  The second instance will be suffixed with "_1".  This is just an alias
Draw join lines between the two tables.
Add selection criteria if necessary.
Select the column you want to update.
Change the query type to Update.
In the Update To line, type the name of the column that contains the data you want in the format -
[tablename].[columnname]
0
 
LVL 31

Expert Comment

by:hnasr
ID: 41871164
Other approach: to avoid hard coding the query.

Create a table u(f, t) with entries from id to id

f          t
8265 8309
------  ------

UPDATE  equipment  inner join u on equipment .local_indicator_id=u.f
set equipment .local_indicator_id =u.t
0
 
LVL 40

Assisted Solution

by:PatHartman
PatHartman earned 1000 total points
ID: 41871221
I don't think the OP actually wants to have literals in the query.  Parameters perhaps, but not literals.  However, if there is no field on which to join the two instances, then a cross reference table might be needed.
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 41872029
Thanks!
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

783 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