January 22, 2009 at 7:31 am
Hi All,
I have a table which contains a master list of stock codes (stoItemMaster) which lives on Server05.
I have another table which contains a list of stock codes (Products) which lives on Server03.
My task is to get all Master stock codes which do not exist in Products to be added to the products tables.
Here is my sql which works if the tables exists on the same server...
ALTER PROCEDURE dbo.JanetsTest
AS
Insert into Products(ProductCode, ProductDescription)
SELECT StoItemMaster.Code, StoItemMaster.Name
FROM StoItemMaster
where not exists(select Products.ProductCode, Products.ProductDescription from Products where Products.ProductCode = StoItemMaster.Code)
GO
Can someone help me with the syntax of getting the information to Server03
Also if need to know how to change the 'where' so that it will only select stoItemMaster record where the productGroup = 'NPD1' or 'NPD2'
Many thanks in advance 🙂
Janet
January 22, 2009 at 8:38 am
You can setup a linked server (see BOL) and then you can do the query like this:
ALTER PROCEDURE dbo.JanetsTest
AS
Insert into Products
(
ProductCode,
ProductDescription
)
SELECT
SIM.StoItemMaster.Code,
SIM.StoItemMaster.Name
FROM
linkedservername.database.schema.StoItemMaster as SIM
where
not exists(select 1 from Products P
where P.ProductCode = SIM.Code)
GO
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply