Executing remote procedure with user-defined table type variable parameter

前端 未结 1 1996
太阳男子
太阳男子 2021-01-06 08:48

I\'m trying to call a remote stored procedure over a linked server. The problem is, one of the required parameters is a user-defined table types.

I can\'t seem to fig

相关标签:
1条回答
  • 2021-01-06 09:19

    Upon further research I discovered that table variables are invalid for remote procedure calls.

    Instead, what I did was called EXEC [REMOTESERVER].[REMOTEDB]..sp_executesql and declared and populated my table variable and called the stored procedure all inside of that.

    Example:

    DECLARE @SQL nvarchar(4000)
    SET @SQL = N'
    DECLARE @tblVar dbo.user_defined_table_type
    -- Code to populate table here
    EXEC dbo.procedure_name (@param1 = @tblVar)
    '
    EXEC [REMOTESERVER].[REMOTEDB]..sp_executesql @stmt = @SQL
    

    And that solved my problem. Hopefully this will help someone else out in the future.

    0 讨论(0)
提交回复
热议问题