使用插入和更新模拟SQL合并

我有两个本地和远程数据库,从本地到远程的一种访问方式。而且我们只能从本地数据库插入和更新远程数据库。我编写了一个合并查询,但是无法在远程执行,因为远程数据库无法访问源数据库,因此我想将其转换为插入和更新命令。如果远程数据库中有一行,则应对其进行更新,如果不存在,则应将其插入

我的合并代码是

MERGE INTO [RemoteIp].[dbname].[dbo].[MTest] AS [Target]
USING (SELECT * FROM [dbo].[Products]
) AS [Source] ([ProductID],[ProductName],[Rate])
 ON ([Target].[PID] = [Source].[ProductID])
  WHEN MATCHED AND (
    NULLIF([Source].[ProductID], [Target].[PID]) IS NOT NULL OR NULLIF([Target].[PID], [Source].[ProductID]) IS NOT NULL OR 
    NULLIF([Source].[ProductName], [Target].[ProductName]) IS NOT NULL OR NULLIF([Target].[ProductName], [Source].[ProductName]) IS NOT NULL OR 
    NULLIF([Source].[Rate], [Target].[Rate]) IS NOT NULL OR NULLIF([Target].[Rate], [Source].[Rate]) IS NOT NULL) THEN
 UPDATE SET
  [Target].[PID] = [Source].[ProductID], 
  [Target].[ProductName] = [Source].[ProductName], 
  [Target].[Rate] = [Source].[Rate]
WHEN NOT MATCHED BY TARGET THEN
 INSERT([PID],[ProductName],[Rate]) 
 VALUES([Source].[ProductID],[Source].[ProductName],[Source].[Rate]);

我尝试此插入和更新

IF EXISTS(SELECT * FROM [RemoteIP].[DBName].[db].[Mtest])
BEGIN
    --update existing row
UPDATE
    [RemoteIP].[DBName].[db].[Mtest]
SET
    [RemoteIP].[DBName].[db].[Mtest].pid = products.ProductID,
    [RemoteIP].[DBName].[db].[Mtest].ProductName = products.ProductName,
    [RemoteIP].[DBName].[db].[Mtest].Rate = products.Rate
FROM
    Mtest INNER JOIN products
        ON [RemoteIP].[DBName].[db].[Mtest].pid = products.ProductID
END
ELSE
BEGIN
    --insert new row
    INSERT INTO [RemoteIP].[DBName].[db].[Mtest] (pid, ProductName, Rate)
    VALUES ([products].[ProductID], [products].[ProductName], [products].[Rate])

在运行查询时出现此错误

The multi-part identifier …… could not be bound in line 12