将参数传递给 T-SQL 节点方法 (XML CROSS APPLY)
当我使用此语法时,出现以下错误。我希望能够将参数传递给节点函数:-
CROSS APPLY XML_TPYE_COLUMN.nodes(@p_Xpath) AS Tab(Col)
错误:
The argument 1 of the XML data type method "nodes" must be a string literal.
有人可以告诉我如何正确执行此操作吗?
I am getting the error below when I use this syntax. I want to be able to pass the argument to the nodes function:-
CROSS APPLY XML_TPYE_COLUMN.nodes(@p_Xpath) AS Tab(Col)
Error:
The argument 1 of the XML data type method "nodes" must be a string literal.
Can someone tell me how do i do this correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须通过动态 sql 来执行此操作,因为节点的参数必须是字符串文字。这与执行
sp_executesql
时执行的操作类似。换句话说,您需要将整个 sql 语句构造为 nvarchar(max) 并将其传递给 sp_executesql:
You'll have to do this via dynamic sql since the parameter for nodes must be a string literal. This is similar to what you do when you do
sp_executesql
.In other words, you need to construct your entire sql statement as nvarchar(max) and pass it to sp_executesql: