简体   繁体   English

将 XML 变量从存储过程传递到 SQL 服务器中的另一个存储过程

[英]Pass XML variable from a stored proc to another stored proc in SQL server

I have 2 stored proc.我有 2 个存储过程。

The first one receive as input parameter some variables and one of them is XML.第一个接收一些变量作为输入参数,其中一个是 XML。

Inside this proc i call another proc but dynamically like that.在这个过程中,我调用另一个过程,但动态地像那样。 This proc handle the XML to insert it in the DB.此过程处理 XML 以将其插入数据库。

SET @SQL = 'EXEC [' + @ServerIp + '].[List_' + CAST(@AccountId AS VARCHAR) + '].[dbo].[psu_proc_name] @ParameterId = ' + CAST(@ParameterId AS VARCHAR) + ',@MappingFields = ' + @MappingFields

@MappingFields is the name of the XML variable in the first proc and also in the second proc (called dynamically) @MappingFields 是第一个过程和第二个过程中的 XML 变量的名称(动态调用)

I manage the treatment of the XML in the second proc (dynamic) but i don't know how to pass the parameter as XML to the second proc.我在第二个过程(动态)中管理 XML 的处理,但我不知道如何将参数作为 XML 传递给第二个过程。

Thanks谢谢

The best way to do this is to use the sp_executesql stored procedure instead of using the simle exec command.最好的方法是使用sp_executesql存储过程,而不是使用 simle exec命令。 See the not duplicate, but very clear examples in the question EXEC sp_executesql with multiple parameters for easy to understand details.请参阅EXEC sp_executesql with multiple parameters问题中的不重复但非常清晰的示例,以便于理解细节。

i've tried something like that:我试过这样的事情:

SET @SQL = N'EXEC [' + @ServerIp + '].[List_' + CAST(@AccountId AS VARCHAR) + '].[dbo].[psu_opensystem_field_mapping_add]'
EXEC sp_executeSQL @SQL, N'@ParameterId INT, @MappingFields XML' , @ParameterId, @MappingFields

But it says that但它说

Procedure or function 'psu_opensystem_field_mapping_add' expects parameter '@ParameterId', which was not supplied

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM