0

I have two databases with stock info. Both of them (among others) contains:

SKU;stock_level

What I want to get is:

SKU;stock_level_warehouse1;stock_level_warehouse2

The SKU's are the same at every warehouse, only stock level could be different. How can I merge data from that two databases by the SQL/T-SQL?


EDIT (Sample Data)

SELECT
    MSSERVER.company1.dbo.vwArticles.article_sku, 
    MSSERVER.company1.dbo.vwArticles.warehouse_id, 
    MSSERVER.company1.dbo.vwArticles.stock_level
FROM
    MSSERVER.company1.dbo.vwArticles
WHERE
    MSSERVER.company1.dbo.vwArticles.warehouse_id = 1

In the second query (that I want merge with this above) everything is the same except company name - there is "company2" instead "company1".

As the result I want to get:

SKU;STOCK_LEVEL_COMAPNY_1;STOCK_LEVEL_COMPANY_2
mrdd
  • 19
  • 4

2 Answers2

0

Without sample data I cannot be certain but you just need to JOIN your tables.

SELECT t1.SKU, t1.stock_level_warehouse1, t2.stock_level_warehouse2
FROM yourtable1 t1
INNER JOIN yourtable2 t2 ON t1.SKU = t2.SKU
Matt
  • 14,906
  • 27
  • 99
  • 149
0

Assuming your two databases are in the same server: Database 1: FooDB Database 2 : FooDB2

select t1.id, t2.descr
from [foodb].[dbo].table1 t1
inner join [foodb2].[dbo].table2 t2
on t1.id = t2.table1id
Alkis Giamalis
  • 300
  • 7
  • 14