Last active
June 4, 2018 20:53
-
-
Save aevdokimenko/527508c722223e4750a2491dc8f22adf to your computer and use it in GitHub Desktop.
Gets remote log records using parameterized openquery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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