sql - How can I easily use TVPs with a linked server? -
the problem:
i using linked server call stored procedures remote server. while works fine of times, have number of stored procedures use table-valued parameters (tvps). mssql cannot call remote sps use parameters tvps.
the workaround execute sql on remote sql , build there tvps. again works fine.
the problem have compose string call sp. in case when have few tvps, more or less easy, have sps lot of tvps.
now, when profiling stored procedure call, call .net sql in case of tvp parameter stored procedure looks like:
declare @p1 <type> insert @p1 values(...) insert @p1 values(...)
...
exec myproc @p1
what want wrapper on server (identical sp remote) , within call remote server exec sql.
does how can (if can) access query stored procedure? access it's own profiler query can send remote ?
ok, solution (that kind of automates half of problem) :
declare @tvpval_string nvarchar(max) = 'declare @tvpval mytvptype;' set tvpval_string += isnull(stuff((select ';insert @tvpval values('+...your values...+')' [text()] @tvpval xml path('')),1,1,'')+';',''); declare @sql nvarchar(max) = tvpval_string + 'exec myproc @tvpval=@tvpval, @otherval=@otherval' exec [remotesrv].db..sp_executesql @sql,'@otherval type',@otherval
Comments
Post a Comment