You can pass the variable to sp_executesql
. You have to declare it as OUTPUT
to receive the value back:
Declare @begin_lsn binary(10)
EXEC LinkedServer.MyDatabase..sp_executesql N'SELECT @begin_lsn = sys.fn_cdc_get_min_lsn(''dbo_td_coater_rga_new'');',
N'@begin_lsn binary(10) OUTPUT', @begin_lsn OUTPUT