473,394 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Update Query Help

I want to write an update query that updates fields from one table to another. The first table (tblCopyFrom) is in a one-to-one relationship with the 2nd (tblCopyTo). The primary key in tblCopyFrom is stored in a foreign key field in tblCopyTo. I want the query to update tblCopyTo to values of the corresponding record in tblCopyFrom where the names of the fields in each table are the same. I know how to do this in VBA with ADODB recordsets, but I was wondering if there is a way to do it with a SQL statement. Any thoughts?

Thanks,
Josh
Feb 15 '07 #1
2 1871
I want to write an update query that updates fields from one table to another. The first table (tblCopyFrom) is in a one-to-one relationship with the 2nd (tblCopyTo). The primary key in tblCopyFrom is stored in a foreign key field in tblCopyTo. I want the query to update tblCopyTo to values of the corresponding record in tblCopyFrom where the names of the fields in each table are the same. I know how to do this in VBA with ADODB recordsets, but I was wondering if there is a way to do it with a SQL statement. Any thoughts?

Thanks,
Josh

I am not quite sure on this but this may help you get started:

Expand|Select|Wrap|Line Numbers
  1. UPDATE tblCopyTo
  2.            Set "FieldName of where you want the data to go" = [tblCopyFrom]!["FiledName fo where you are getting the data from"]
  3.            Where "Foriegn Key Field" = [tblCopyFrom]!["Primary Key Field]
Where I have the quotes around things that is just to represent fields, you do not need the quotes. And like I said I am not quite sure if the syntax is right, it probably isn't, but it will help you get started.
Feb 15 '07 #2
ADezii
8,834 Expert 8TB
I want to write an update query that updates fields from one table to another. The first table (tblCopyFrom) is in a one-to-one relationship with the 2nd (tblCopyTo). The primary key in tblCopyFrom is stored in a foreign key field in tblCopyTo. I want the query to update tblCopyTo to values of the corresponding record in tblCopyFrom where the names of the fields in each table are the same. I know how to do this in VBA with ADODB recordsets, but I was wondering if there is a way to do it with a SQL statement. Any thoughts?

Thanks,
Josh
Expand|Select|Wrap|Line Numbers
  1. UPDATE tblCopyFrom INNER JOIN tblCopyTo
  2.     ON tblCopyFrom.PrimaryKey = tblCopyTo.ForeignKey
  3. SET tblCopyTo.SomeField = tblCopyFrom!SomeField;
Feb 15 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Surendra | last post by:
I have this query that I need to use in an Update statement to populate a field in the table by the value of Sq ---------------------------------------------------------------------------- Inline...
2
by: Mike Leahy | last post by:
Hello all, This question is related to updating tables - is there any way to calculate or update the values in a column in a table to the values in a field produced by a query result? An...
1
by: Kunal | last post by:
Hi, I need some help on writing an update query to update "UnitsSold" field in Products Table whenever I save a transaction. The transaction may contain several "Subtransactions", one for each...
10
by: Randy Harris | last post by:
I imported records into a table, later found out that many of them had trailing spaces in one of the fields. If I'd caught it sooner, I could have trimmed the spaces before the import. This...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
7
by: Mark Carlyle via AccessMonster.com | last post by:
I have this update query that I am trying to run. I know the syntax is messed up but do not know how to correct it. Select 'UPDATE', Transactions,'Set = where = ' From "Get Daily Balances" ...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
8
by: rriness | last post by:
I'm getting an inconsistent failure when trying to save data in ADO.Net. I'm using an Access database with a simple query - SELECT StudentID, FirstName, LastName FROM Students - and have no...
3
by: eholz1 | last post by:
Hello PHP programmers. I had a brilliant idea on one of my pages that selects some data from my mysql database. I first set the page up to display some info and an image, just one item, with a...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.