Greeting!
I have 2 server:
Server 1
Server 2(Local)
I had created the linked server in my Server2 (linked server- SERVER1). I was attempting to create a query to get the data from the Server1, if Server2 doesn't have the data as Server1 then insert the data into Server2. It was successful execute the data from Server1 but it doesn't insert into Server2 (Local). Please advice me.
Here is my query:
SELECT * FROM OPENQUERY (SERVER1, 'SELECT EmployeeID, EmployeeName, JoinDate, CAST([XMLContent] AS NVARCHAR(MAX)) FROM dbo.Computer.tblEmployee WHERE JoinDate >= ''2016-02-29''')IF NOT EXISTS
(SELECT * FROM OPENQUERY ([SERVER2], 'SELECT EmployeeID, EmployeeName, JoinDate, CAST([XMLContent] FROM dbo.Computer.tblEmployee'))
INSERT INTO Computer.tblEmployee SELECT * FROM OPENQUERY ([SERVER2], 'SELECT EmployeeID, EmployeeName, JoinDate, CAST([XMLContent] FROM dbo.Computer.tblEmployee')