Return Function value in variable with Open Query on Remote SQL Server Database

Recently I received a request from Development Team on how we can get a function value returned from a remote sql server instance.

DECLARE @CTVAL int 
Select @CTVAL = VERSION_TEST from 
  Openquery([Remote SQL Instance],'DECLARE @var VARCHAR(100) SET @var = ''USE DatabaseName; 
                   select CHANGE_TRACKING_CURRENT_VERSION() AS VERSION_TEST''; EXECUTE(@var) ') 

UPDATE [DatabaseName].[dbo].[TableName] SET ConfigValue= @CTVAL WHERE ConfigKey='Condition Value'
 

Leave a Reply

Your email address will not be published. Required fields are marked *