<tfoot id='u0ADK'></tfoot>
  • <small id='u0ADK'></small><noframes id='u0ADK'>

          <bdo id='u0ADK'></bdo><ul id='u0ADK'></ul>
      1. <i id='u0ADK'><tr id='u0ADK'><dt id='u0ADK'><q id='u0ADK'><span id='u0ADK'><b id='u0ADK'><form id='u0ADK'><ins id='u0ADK'></ins><ul id='u0ADK'></ul><sub id='u0ADK'></sub></form><legend id='u0ADK'></legend><bdo id='u0ADK'><pre id='u0ADK'><center id='u0ADK'></center></pre></bdo></b><th id='u0ADK'></th></span></q></dt></tr></i><div id='u0ADK'><tfoot id='u0ADK'></tfoot><dl id='u0ADK'><fieldset id='u0ADK'></fieldset></dl></div>

        <legend id='u0ADK'><style id='u0ADK'><dir id='u0ADK'><q id='u0ADK'></q></dir></style></legend>

        使用 Xquery 在 sql server 中查询 XML 列表

        时间:2023-06-05

        <tfoot id='c13lt'></tfoot>
          <bdo id='c13lt'></bdo><ul id='c13lt'></ul>
          <legend id='c13lt'><style id='c13lt'><dir id='c13lt'><q id='c13lt'></q></dir></style></legend>
          <i id='c13lt'><tr id='c13lt'><dt id='c13lt'><q id='c13lt'><span id='c13lt'><b id='c13lt'><form id='c13lt'><ins id='c13lt'></ins><ul id='c13lt'></ul><sub id='c13lt'></sub></form><legend id='c13lt'></legend><bdo id='c13lt'><pre id='c13lt'><center id='c13lt'></center></pre></bdo></b><th id='c13lt'></th></span></q></dt></tr></i><div id='c13lt'><tfoot id='c13lt'></tfoot><dl id='c13lt'><fieldset id='c13lt'></fieldset></dl></div>

                <tbody id='c13lt'></tbody>

              <small id='c13lt'></small><noframes id='c13lt'>

                • 本文介绍了使用 Xquery 在 sql server 中查询 XML 列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我在 SQL Server 中有一个表,用于存储提交的表单数据.每次提交的表单字段都是动态的,因此收集的数据作为名称值对存储在名为 [formdata] 的 XML 数据列中,如下例所示...

                  I have a table in SQL server that is used to store submitted form data. The form fields for each submission are dynamic so the collected data is stored as name value pairs in an XML data column called [formdata] as in the example below...

                  这可以很好地收集所需的信息,但我现在需要将这些数据呈现到平面文件或 Excel 文档中以供工作人员处理,我想知道使用 Xquery 的最佳方法是什么,以便数据可读吗?

                  This works fine for collecting the required information but I now need to render this data to a flat file or an excel document for processing by human staff members and im wondering what the best way of doing this would be using Xquery so that the data is readable?

                  表格如下...

                  [id], [user_id], [datestamp], [formdata]
                  

                  以及 formdata 的示例值

                  And a sample value for formdata

                  <formfields>
                    <item>
                      <itemKey>USER_NAME</itemKey>
                      <itemValue>test</itemValue>
                    </item>
                    <item>
                      <itemKey>value2</itemKey>
                      <itemValue>test</itemValue>
                    </item>
                    <item>
                      <itemKey>MYID</itemKey>
                      <itemValue>5468512</itemValue>
                    </item>
                    <item>
                      <itemKey>testcheckbox</itemKey>
                      <itemValue>item1,item3</itemValue>
                    </item>
                    <item>
                      <itemKey>samplevalue</itemKey>
                      <itemValue>item3</itemValue>
                    </item>
                    <item>
                      <itemKey>accept_terms</itemKey>
                      <itemValue>True</itemValue>
                    </item>
                  </formfields>
                  

                  推荐答案

                  这是您想要的吗?

                  select
                    id,
                    [user_id],
                    datestamp,
                    f.i.value('itemKey[1]', 'varchar(50)') as itemKey,
                    f.i.value('itemValue[1]', 'varchar(50)') as itemValue
                  from YourTable as T
                    cross apply T.formdata.nodes('/formfields/item') as f(i)
                  

                  测试:

                  declare @T table
                  (
                    id int,
                    user_id int,
                    datestamp datetime,
                    formdata xml
                  )
                  
                  insert into @T (id, user_id, datestamp, formdata)
                  values (1, 1, getdate(),
                  '<formfields>
                    <item>
                      <itemKey>USER_NAME</itemKey>
                      <itemValue>test</itemValue>
                    </item>
                    <item>
                      <itemKey>value2</itemKey>
                      <itemValue>test</itemValue>
                    </item>
                    <item>
                      <itemKey>MYID</itemKey>
                      <itemValue>5468512</itemValue>
                    </item>
                    <item>
                      <itemKey>testcheckbox</itemKey>
                      <itemValue>item1,item3</itemValue>
                    </item>
                    <item>
                      <itemKey>samplevalue</itemKey>
                      <itemValue>item3</itemValue>
                    </item>
                    <item>
                      <itemKey>accept_terms</itemKey>
                      <itemValue>True</itemValue>
                    </item>
                  </formfields>
                  '
                  )
                  
                  select
                    id,
                    [user_id],
                    datestamp,
                    f.i.value('itemKey[1]', 'varchar(50)') as itemKey,
                    f.i.value('itemValue[1]', 'varchar(50)') as itemValue
                  from @T as T
                    cross apply T.formdata.nodes('/formfields/item') as f(i)
                  

                  结果:

                  id  user_id  datestamp                itemKey       itemValue
                  1   1        2011-05-23 15:38:55.673  USER_NAME     test
                  1   1        2011-05-23 15:38:55.673  value2        test
                  1   1        2011-05-23 15:38:55.673  MYID          5468512
                  1   1        2011-05-23 15:38:55.673  testcheckbox  item1,item3
                  1   1        2011-05-23 15:38:55.673  samplevalue   item3
                  1   1        2011-05-23 15:38:55.673  accept_terms  True
                  

                  这篇关于使用 Xquery 在 sql server 中查询 XML 列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何返回 SQL Server XPath 中存在的值? 下一篇:带有 CDATA 块的 SQL Server XML 数据

                  相关文章

                  最新文章

                  <tfoot id='SQFXr'></tfoot>
                • <legend id='SQFXr'><style id='SQFXr'><dir id='SQFXr'><q id='SQFXr'></q></dir></style></legend>

                      <i id='SQFXr'><tr id='SQFXr'><dt id='SQFXr'><q id='SQFXr'><span id='SQFXr'><b id='SQFXr'><form id='SQFXr'><ins id='SQFXr'></ins><ul id='SQFXr'></ul><sub id='SQFXr'></sub></form><legend id='SQFXr'></legend><bdo id='SQFXr'><pre id='SQFXr'><center id='SQFXr'></center></pre></bdo></b><th id='SQFXr'></th></span></q></dt></tr></i><div id='SQFXr'><tfoot id='SQFXr'></tfoot><dl id='SQFXr'><fieldset id='SQFXr'></fieldset></dl></div>
                    1. <small id='SQFXr'></small><noframes id='SQFXr'>

                        <bdo id='SQFXr'></bdo><ul id='SQFXr'></ul>