We help IT Professionals succeed at work.
Get Started

Updating SQL Server 2010 table using another table

105 Views
Last Modified: 2017-10-31
Hello All:

I have two tables (shown below) Orders and OrdersUpdate.  What I am trying to do is update the orders table with the new order numbers located in the OrdersUpdate table.  What I have to do is join them on three fields, Order, M1, and M2, and have a date range between 10/15/2017 and 10/21/2017.  I've tried using Inner Join joining on the OrdersUpdate Table three times (just selecting to see if data is retrieved -

SELECT * FROM Orders o
INNER JOIN OrdersUpdate ou1 ON o.Order = ou1.Order
INNER JOIN OrdersUpdate ou2 ON o.M1 = ou2.M1
INNER JOIN OrdersUpdate ou3 ON o.M2 = ou2.M2
WHERE o.Date BETWEEN '10/15/2017' AND '10/21/2017'

but that is not returning anything, and I know there is data there.

Can someone please assist in helping me correctly join these tables so that I can update the old order numbers with the new order numbers?

Orders Table
OrdersUpdate Table
After UpdateMany thanks!

Juan
Comment
Watch Question
Database Expert
Awarded 2016
Top Expert 2016
Commented:
This problem has been solved!
Unlock 3 Answers and 9 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE