使用 TSQL 变量 + X查询
所有,
我有以下代码:
--xml is already declared and populated with an xml document
SELECT
ent.query('TradeId').value('.','VARCHAR(10)') TradeId
FROM
@xml.nodes('//table/trade[1]') Col(ent)
如何将表达式 //table/trade[1] 作为变量,以便我可以在循环中增加 [1] ?例如,我想要像下面这样不起作用的东西:
DECLARE @KLM varchar(100)
SET @KLM= '//table/trade[1]'
SELECT
ent.query('TradeId').value('.','VARCHAR(10)') TradeId
FROM
@xml.nodes(@KLM) Col(ent)
有什么想法吗?
谢谢,
米
All,
I have the following code:
--xml is already declared and populated with an xml document
SELECT
ent.query('TradeId').value('.','VARCHAR(10)') TradeId
FROM
@xml.nodes('//table/trade[1]') Col(ent)
How can I have the expression //table/trade[1] as a variable so I can increase the [1] in a loop ? For example I would like something like the below which is not working:
DECLARE @KLM varchar(100)
SET @KLM= '//table/trade[1]'
SELECT
ent.query('TradeId').value('.','VARCHAR(10)') TradeId
FROM
@xml.nodes(@KLM) Col(ent)
Any ideas?
Thanks,
M
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果从 .nodes() 方法中删除位置引用,您应该获得包含所有 TradeId 值的结果集。
然后,您应该能够迭代该结果集,尽管我想添加关于“关系模型中的迭代通常是一个坏主意”的标准警告。
这有帮助吗?如果没有,这个故事还有更多内容吗?
If you remove the positional reference from your .nodes() method, you should get a resultset containing all of the TradeId values.
You should then be able to iterate through that resultset, although I would like to add the standard caveat about "iteration in a relational model is generally a bad idea".
Does that help? If not, is there more to the story?