set @sql = replace(replace('
declare @updateCount int = (
select count(*)
from openquery($svr$, ''select * from $db$.target'') a
inner join openquery($svr$, ''select * from $db$.target_info where filter1=11 and filter2=22'') b on a.target_info_id = b.id
inner join SomeOtherDb.dbo.SourceOfTruth i on b.key=i.Key
where a.something <> i.Something);
declare @msg nvarchar(max) = concat(''Updating [target]: '', @updateCount, '' rows.'');
exec SomeOtherDb.dbo.LogEntry ''DYNSQL@$svr$.$db$'', @msg;