Skip to content

Instantly share code, notes, and snippets.

@aevdokimenko
Last active June 4, 2018 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aevdokimenko/527508c722223e4750a2491dc8f22adf to your computer and use it in GitHub Desktop.
Save aevdokimenko/527508c722223e4750a2491dc8f22adf to your computer and use it in GitHub Desktop.
Gets remote log records using parameterized openquery
declare @sql nvarchar(1000), @lastdate varchar(20)
-- looking for the data for the last 72 hours
select @lastdate = datediff(S,'1970-01-01', dateadd(hour, -72, getdate()))
print '--> Executing GetLog -->
SQL:'
select @sql = '
select distinct
partition,
time = dateadd(S, [time_id], ''1970-01-01''),
data1, data2, data3, data4, data5
from openquery(LINKED_SERVER_1,
''select *
from log
where time_id >=' + @lastdate + ''')'+
' except select * from log'
print @sql
insert log
Exec sp_executesql @sql
print '<-- Exiting GetLog --'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment