Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Compare and update data between two databases

Posted on 2016-10-04
6
Medium Priority
?
99 Views
Last Modified: 2016-10-04
Hi,

I was helped by one of the members with the query below, but a closer look at the query doesn't works. Any assistance greatly appreciated. Thanks!

Here is the query:

USE Inventory
GO
UPDATE Items
SET [Available Inventory] = (SELECT [Available Inventory]
        FROM Items_Update.. Updates U
        WHERE U.[Item Number] = Items.[Item Number])


Example per screenshot:
- The query compare the 'Item Number' between the Inventory and Items_Update databases.
- If the Item Number matches, then update the "Available Inventory" number, which is 22 to the "Available Inventory" field in the Inventory database.
0
Comment
Question by:Member_2_7967487
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 

Author Comment

by:Member_2_7967487
ID: 41829185
Example1.jpg
0
 
LVL 30

Accepted Solution

by:
Pawan Kumar earned 2000 total points
ID: 41829191
Pls try this..

USE Inventory
GO

UPDATE a
SET a.[Available Inventory] = U.[Available Inventory]
FROM Items a
INNER JOIN Items_Update.. Updates U
ON U.[Item Number] = a.[Item Number] 

Open in new window

0
 
LVL 30

Expert Comment

by:Pawan Kumar
ID: 41829210
Have you tried the above approach?
0
Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

 

Author Comment

by:Member_2_7967487
ID: 41829214
I have an error.



errorA.jpg
0
 
LVL 30

Expert Comment

by:Pawan Kumar
ID: 41829216
can you provide me the schema for both the tables ?
0
 

Author Comment

by:Member_2_7967487
ID: 41829220
I updated the line below and it works!  Thank you very much, Pawan!!
[ Available Inventory ]

SET a.[Available Inventory] = U.[ Available Inventory ]
0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

705 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