Solved

Compare and update data between two databases

Posted on 2016-10-04
6
57 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
  • 3
  • 3
6 Comments
 

Author Comment

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

Accepted Solution

by:
Pawan Kumar earned 500 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 23

Expert Comment

by:Pawan Kumar
ID: 41829210
Have you tried the above approach?
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:Member_2_7967487
ID: 41829214
I have an error.



errorA.jpg
0
 
LVL 23

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

929 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now