Hi, the code below works fine but it takes an absolute age to run. How can I speed this up?
Background: I have linked my local server to my remote server. From my local server, I need to insert data from the remote server into my local server and then update the table on my remote server. See snippet for the exact details.
DECLARE @temp1 TABLE
(LoginID INT PRIMARY KEY,
UserID UNIQUEIDENTIFIER,
Message NCHAR(1000))
INSERT INTO [My Local Server].[DB Name].dbo.Login
(LoginID, UserID, Message)
OUTPUT INSERTED.LoginID, INSERTED.UserID, INSERTED.Message INTO @temp1
SELECT LoginID, UserID, Message
FROM [Remote Server].[Remote DB Name].dbo.Login2
WHERE Date IS NULL
UPDATE [Remote Server].[Remote DB Name].dbo.Login2
SET Date = GETDATE()
FROM [Remote Server].[Remote DB Name].dbo.Login2 AS z
WHERE EXISTS (SELECT 1 FROM @temp1 AS x WHERE z.Date IS NULL AND x.LoginID = z.LoginID)
EDIT:
In addition, is there anyway I can compress/zip the data being sent back and forth?