Update YourTable2 As T2
Set T2.July =
(Select T1.Quantity
From YourTable1 As T1
Where T1.Company = T2.Company)
Main Topics
Browse All TopicsHi,
I have a table contaning Quantity, Company fields, I have another table contaning July, Company fields.
I need to transfer the Quantity from the first database to the july field in the second database where the company in the first database is = to the company in the second database.
I would like to use the sql update statement,
How will I do this?
The database is paradox.
Thanks
Asw
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
ASW,
<but if the company has 2 orders for july then I get an error: Single row subquery produced more than 1 row.>
What you have asked us is to provide an Update query for your two tables. It appears that what you would LIKE to do (use a single SQL Update statement) is not possible in your production environment. Here are some questions for us all.
1) Do both/all of these multiple July entries contain valid data?
2) Is it acceptable to drop/ignore one of these July entries?
3) Is one of these July entries more valid? (supercedes)
4) If 3) is true, what criteria is used to select the most valid row?
One simple work-around is:
(Select FIRST T1.sumQuantity ...
or
(Select LAST T1.sumQuantity ...
I'm not sure if the FIRST or LAST keywords are supported by your database engine.
Other solutions require us to use a datetime field or autonumber field as a tie-breaker. We don't know that much detail about the tables' definitions.
==========================
I think there's something flawed with the design or data validation if there are multiple records, then some other processing must take place before updating the table, as mocarts comment indicates -- sum the quantity field before updating.
==========================
mocarts,
Is the Group By really necessary? This should work:
(Select SUM(T1.Quantity) From YourTable1 As T1 Where T1.Company = T2.Company)
Business Accounts
Answer for Membership
by: bpanaPosted on 2004-02-28 at 06:29:54ID: 10476043
for SQL Server:
update T2
set T2.July = T1.Quantity
from YourTable1 T1, YourTable2 T2
where T1.Company = T2.Company
maybe is the same for paradox tables