Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two tables on two server with same definition.
every days some entries enter in server1 tables.
now for that one day entry. I want to copy data on second server table for every day.

to establish connection between two server i created link server.
I have created query to copy all data from one server to another that working fine (following query)
INSERT INTO [server2].[RemedyIntegration].[dbo].[tbl_Insert_Data]
SELECT * from  [server1].[ABC_Test_Link_Vin].[dbo].[tbl_Insert_Data]


but now i want to create query to copy one day data from server A to B.

for that I have written query as follows.

INSERT INTO [server2].[RemedyIntegration].[dbo].[tbl_Insert_Data]
SELECT * from  [server1].[ABC_Test_Link_Vin].[dbo].[tbl_Insert_Data]
where [server2].[RemedyIntegration].[dbo].[tbl_Insert_Data].ID
 not in (select I.ID from [server2].[RemedyIntegration].[dbo].[tbl_Insert_Data] as i inner join [server1].[ABC_Test_Link_Vin].[dbo].[tbl_Insert_Data] as tblins on I.ID=tblins.ID)


but it gives error as
The multi-part identifier "server2.RemedyIntegration.dbo.tbl_Insert_Data.ID" could not be bound.


What I have tried:

INSERT INTO [server2].[RemedyIntegration].[dbo].[tbl_Insert_Data]
SELECT * from  [server1].[ABC_Test_Link_Vin].[dbo].[tbl_Insert_Data]
where [server2].[RemedyIntegration].[dbo].[tbl_Insert_Data].ID
 not in (select I.ID from [server2].[RemedyIntegration].[dbo].[tbl_Insert_Data] as i inner join [server1].[ABC_Test_Link_Vin].[dbo].[tbl_Insert_Data] as tblins on I.ID=tblins.ID)


please suggest what will be my condition
Posted
Updated 23-Feb-20 22:55pm

You're trying to use a five-part identifier for the column, which won't work. Try adding an alias to the table.

Also, the INNER JOIN within the NOT IN nested query doesn't make any sense to me. You're already selecting from server1, so you don't need to join to it again in the nested query.
SQL
INSERT INTO [server2].[RemedyIntegration].[dbo].[tbl_Insert_Data]
SELECT * FROM [server1].[ABC_Test_Link_Vin].[dbo].[tbl_Insert_Data] As S
WHERE S.ID NOT IN 
(
    SELECT I.ID 
    FROM [server2].[RemedyIntegration].[dbo].[tbl_Insert_Data] As I 
)
Or:
SQL
INSERT INTO [server2].[RemedyIntegration].[dbo].[tbl_Insert_Data]
SELECT * FROM [server1].[ABC_Test_Link_Vin].[dbo].[tbl_Insert_Data] As S
WHERE NOT EXISTS
(
    SELECT I.ID 
    FROM [server2].[RemedyIntegration].[dbo].[tbl_Insert_Data] As I 
    WHERE I.ID = S.ID
)
 
Share this answer
 
Double-check the name of the columns. You could also try to put the column name between square brackets ([ID]).

sql - What is a 'multi-part identifier' and why can't it be bound? - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900