Based on this answer I am trying to make a DELETE from a JOIN. The query works if both of the tables are on the same server, but now I have two server:
TableAis onDatabaseAthat is onServerASQL Server 9.0.4060TableBis onDatabaseBthat is onServerBSQL Server 12.0.2000
ServerA is a linked server on ServerB.
I have the following TableA (on ServerA)
+---------+-----------+------+
| Name | Surname | Side |
+---------+-----------+------+
| Anakyn | Skywalker | Bad |
| Luke | Skywaler | Good |
| Obi Wan | Kenobi | Good |
| Anakyn | Skywalker | Good |
| Qui gon | Jinn | Good |
| Darth | Maul | Bad |
+---------+-----------+------+
and the following TableB (on ServerB)
+----------+------+
| Surname | Side |
+----------+------+
| Skywaler | Good |
| Maul | Bad |
+----------+------+
If I execute this query
DELETE A
FROM [ServerA].[DatabaseA].[dbo].[TableA] A
INNER JOIN [dbo].[TableB] B
ON A.[Surname]=B.[Surname] COLLATE Latin1_General_CI_AS
AND A.[Side]=B.[Side] COLLATE Latin1_General_CI_AS
the system gives me an error
OLE DB provider "SQLNCLI11" for linked server "ServerB" returned message "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.". Msg 7202, Level 11, State 2, Line 16 Could not find server 'ServerB' in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers.
Additional consideration:
- The query
select * from sys.servers where is_linked = 1executed on ServerB.DatabaseB show me that ServerA is a linked server; - If replace
DELETE AwithSELECT A.*the query show me the correct results that I would like to delete; - I have checked the INFORMATION_SCHEMA.COLUMNS and every columns of the join have
SQL_Latin1_General_CP1_CI_AScollation; - From [ServerB] I can delete rows of [ServerA].[DatabaseA].[TableA] if I use a
DELETEwithout theJOIN.
Anybody have any help for me?