根据参数值执行XQuery SQL

发布于 2024-11-05 17:59:15 字数 1344 浏览 0 评论 0原文

我的 XML 如下所示:

 <Product sequence_number="1" number="1543448904" id="S1" unit_number="1">

     <consumer_narrative name="GLENN,GREGORY" date_filed="02/13/2009">
        <message type="Consumer Comments">THE CONSUMER STATES THIS WAS  NOT </message>
        <message type="Consumer Comments">THE PRODUCT REQUESTED.</message>
     </consumer_narrative></Product> <Product sequence_number="2" number="1543448905" id="S1" unit_number="1">

     <consumer_narrative name="JOHN,GORDON" date_filed="08/23/2009">
        <message type="Consumer Comments">THE CONSUMER STATES THAT</message>
        <message type="Consumer Comments">WRONG PRODUCT WAS SENT.</message>
     </consumer_narrative>  </Product>

我的查询:

SELECT 

    tab.col.value('../../@number', 'varchar(30)')   [Claim Number], 
    tab.col.value('../@name', 'varchar(30)')   [Name], 
    tab.col.value('../@date_filed', 'varchar(30)')   [DateField],
    tab.col.value('@type', 'varchar(50)')   [Type], 
    tab.col.value('.', 'varchar(250)')   [CustomerComments]

FROM XMLTABLE AS B
CROSS APPLY xmldocument.nodes('//Product/consumer_narrative/message') tab(col)
WHERE B.XMLId = 123

我想传递“number”作为参数,并仅获取与该索赔编号关联的数据。 提前致谢。

This is how my XML looks like :

 <Product sequence_number="1" number="1543448904" id="S1" unit_number="1">

     <consumer_narrative name="GLENN,GREGORY" date_filed="02/13/2009">
        <message type="Consumer Comments">THE CONSUMER STATES THIS WAS  NOT </message>
        <message type="Consumer Comments">THE PRODUCT REQUESTED.</message>
     </consumer_narrative></Product> <Product sequence_number="2" number="1543448905" id="S1" unit_number="1">

     <consumer_narrative name="JOHN,GORDON" date_filed="08/23/2009">
        <message type="Consumer Comments">THE CONSUMER STATES THAT</message>
        <message type="Consumer Comments">WRONG PRODUCT WAS SENT.</message>
     </consumer_narrative>  </Product>

My Query :

SELECT 

    tab.col.value('../../@number', 'varchar(30)')   [Claim Number], 
    tab.col.value('../@name', 'varchar(30)')   [Name], 
    tab.col.value('../@date_filed', 'varchar(30)')   [DateField],
    tab.col.value('@type', 'varchar(50)')   [Type], 
    tab.col.value('.', 'varchar(250)')   [CustomerComments]

FROM XMLTABLE AS B
CROSS APPLY xmldocument.nodes('//Product/consumer_narrative/message') tab(col)
WHERE B.XMLId = 123

I would like to pass "number" as parameter and get only the data associated with that claim number.
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满意归宿 2024-11-12 17:59:15
DECLARE @cnumber AS INT

....

CROSS APPLY xmldocument.nodes('//Product[@number = sql:variable("@cnumber")]/consumer_narrative/message') tab(col) 
DECLARE @cnumber AS INT

....

CROSS APPLY xmldocument.nodes('//Product[@number = sql:variable("@cnumber")]/consumer_narrative/message') tab(col) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文