SQL SELECT .... NOT IN query

137 Views Asked by At

I have created a linked server for accessing an online DB so that I can select new records from the online DB and insert them to the local DB based on the customer ID. Here is my query for selecting new records:

SELECT * FROM [194.0.252.151].onlineDB.dbo.customers 
WHERE [194.0.252.151].onlineDB.dbo.customers.CustomerID 
NOT IN 
(SELECT CustomerID FROM LocalDB.dbo.customers)

Let me say, operations like selection from onlineDB works just fine, but the above code doesn't return the required (new) records from onlineDB. The error says:

The multi-part identifier "194.0.252.151.onlineDB.dbo.customers.CustomerID" could not be bound.

I can't figure out the mistake I have made. Any help would be appreciated.

1

There are 1 best solutions below

0
On BEST ANSWER

You don't need to specify the server name in front of column

Please go for

SELECT * FROM [194.0.252.151].onlineDB.dbo.customers 
WHERE CustomerID 
NOT IN 
(SELECT CustomerID FROM LocalDB.dbo.customers)

I think it should work