문제

I have the following query I'm executing against a remote SQL Server:

EXEC LinkedServer.MyDatabase..sp_executesql N'SELECT sys.fn_cdc_get_min_lsn(''dbo_td_coater_rga_new'');';

The query works fine, but I'm not sure how to capture the results of the query and stored it to a variable. For example, this does not work:

Declare @begin_lsn binary(10)

Set @begin_lsn = EXEC LinkedServer.MyDatabase..sp_executesql N'SELECT sys.fn_cdc_get_min_lsn(''dbo_td_coater_rga_new'');';
도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top