Why the heck is Link Server so much slower than a connection in SSIS (OLE DB), going to a vendor database? It is the exact same server, database and credentials.
For this reason, I need to do this in SSIS.
The vendor database has about, lets say, 1,000 tables. I need to go through every table and grab the latest records which one thing in common for all tables is that it has a field: Processed_Date
So the basic query will be like this:
SELECT * FROM ?
WHERE Processed_Date = GETDATE()
The result of each table needs to be INSERT into the corresponding table or a SELECT INTO in my local database.
I cannot use OLE DB Source and Destination control because that would require manual mapping. I would like to keep this dynamic by table names.
I was able to achieve this with LinkServer & OpenQuery but I can probably run to Alaska and back by the time it finish.
USE [MyTestDatabase]
SET LOCK_TIMEOUT -1
--PURPOSE: Drop Tables
EXEC sp_MSForEachTable @command1 =
'
DROP TABLE [MyTestDatabase].?
'
, @whereand = 'AND o.Name LIKE ''zTEMP_%'' '
--PURPOSE: Load Tables
EXEC sp_MSForEachTable @command1 =
'
DECLARE @TableName AS VARCHAR(255) = REPLACE( REPLACE( REPLACE(''?'', ''['', ''''), '']'', ''''), ''MySchema.'', '''')
DECLARE @MAXModifiedUtc AS VARCHAR(100) = (SELECT MAX(ModifiedUtc) FROM ?)
DECLARE @SQL AS VARCHAR(MAX) =
''SET LOCK_TIMEOUT -1'' + CHAR(13) + CHAR(10) +
''SELECT * INTO [MyTestDatabase].[dbo].zTEMP_'' + @TableName + '' FROM OPENQUERY'' + CHAR(13) + CHAR(10) +
''(MyLinkServer, '' + CHAR(13) + CHAR(10) +
'''''''' + CHAR(13) + CHAR(10) +
''SELECT * FROM '' + @TableName + CHAR(13) + CHAR(10) +
''WHERE ModifiedUtc > '' + @MAXModifiedUtc + CHAR(13) + CHAR(10) +
'''''''' + CHAR(13) + CHAR(10) +
'')''
EXEC(@SQL)
'
, @whereand = 'AND o.Name NOT LIKE ''zTEMP_%'' '