SQL SELECT .... NOT IN query

I created a linked server to access the online database so that I can select new records from the online database and insert them into the local database based on the client ID. Here is my query for selecting new entries:

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 that operations like selecting from onlineDB work very well, but the above code does not return the required (new) entries from onlineDB. The error says:

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

I can’t understand what mistake I made. Any help would be appreciated.

+4
source share
1 answer

You do not need to specify the server name in front of the column

Go through

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

I think it should work

+6
source

Source: https://habr.com/ru/post/1501266/


All Articles