久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

    <tfoot id='mY5FN'></tfoot>

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

        SQL 數據作為 XML 元素

        SQL Data as XML Element(SQL 數據作為 XML 元素)

        • <bdo id='jh5eQ'></bdo><ul id='jh5eQ'></ul>

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

                    <tbody id='jh5eQ'></tbody>
                  <legend id='jh5eQ'><style id='jh5eQ'><dir id='jh5eQ'><q id='jh5eQ'></q></dir></style></legend>

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

                  本文介紹了SQL 數據作為 XML 元素的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我對用 SQL 生成 XML 有點陌生.我正在嘗試從此查詢生成 XML:

                  I am somewhat new on generating XML out with SQL. I am trying to generate XML from this query:

                  SELECT RptType, DataType, Branch, ACC, Actual 
                  FROM ReportingTb
                  

                  查詢產生以下結果:

                  RptType   DataType   Branch    Acc    Actual
                  -------   --------   -------   ----   -----------
                  MTD       UPS        Arizona   Total  2279.00000
                  MTD       UPS        Arizona   Oral   543.00000
                  MTD       UPS        Arizona   Tube   532.00000
                  MTD       UPS        Arizona   Other  1.00000
                  

                  我想將前 4 列中的查詢結果實際用作 XML 元素,如下所示:

                  I want to use the query results in the first 4 columns the actual as XML elements like this:

                  <MTD>
                    <UPS>
                      <Arizona>
                        <Total>
                          <Actual>2279.00000</Actual>
                        </Total>
                        <Oral>
                          <Actual>543.00000</Actual>
                        </Oral>
                        <Tube>
                          <Actual>532.00000</Actual>
                        </Tube>
                        <Other>
                          <Actual>1.00000</Actual>
                        </Other>
                      </Arizona>
                    <UPS>
                  </MTD>
                  

                  有人能指出我正確的方向嗎?我應該使用 T-SQL 并遍歷查詢結果以制作 XML 文件嗎?

                  Can someone point me in the right direction on how to do this? Should I maybe use T-SQL and loop through the results of the query in order make the XML file?

                  感謝您的幫助!

                  推薦答案

                  這在技術上是可行的,但由于一些原因,它確實很糟糕.相反,您應該重新考慮您的 XML 結構,使其更像這樣:

                  It's technically possible, but it's really bad for a few reasons. Instead, you should rethink your XML structure, to something more like this:

                  <Root>
                    <ReportingTb RptType="MTD" DataType="UPS" Branch="Arizona">
                      <Actual Acc="Total">2279.00000</Actual>
                      <Actual Acc="Oral">543.00000</Actual>
                      <Actual Acc="Tube">532.00000</Actual>
                      <Actual Acc="Other">1.00000</Actual>
                    </ReportingTb>
                  </Root>
                  

                  使用此查詢:

                  DECLARE @t TABLE (RptType varchar(20),   DataType VARCHAR(20),   Branch VARCHAR(20),    Acc VARCHAR(20),   Actual numeric(10,5));
                  INSERT @t VALUES
                  ('MTD',  'UPS'        ,'Arizona',   'Total',  2279.00000)
                  ,('MTD',  'UPS'        ,'Arizona',   'Oral',  543.00000)
                  ,('MTD',  'UPS'        ,'Arizona',   'Tube',  532.00000)
                  ,('MTD',  'UPS'        ,'Arizona',   'Other',  1.00000);
                  
                  SELECT RptType as '@RptType'
                      ,DataType as '@DataType'
                      ,Branch as '@Branch'
                      ,(SELECT 
                           Acc AS '@Acc'
                          ,Actual as '*'
                      FROM @t t2
                      WHERE t2.RptType = t1.RptType AND t2.DataType = t1.DataType AND t2.Branch = t1.Branch
                      FOR XML PATH('Actual'), TYPE)
                  FROM @t t1
                  GROUP BY RptType, DataType, Branch
                  FOR XML PATH('ReportingTb'), ROOT('Root');
                  

                  這為您提供了可以根據模式(而不是必須包含許多可能的節點名稱的模式)進行合理驗證的 XML.它將更自然地處理不同的分組可能性,并將處理 FOR XML 在幕后處理的所有 XML 怪異現象.

                  This gives you XML that can be sensibly validated against a schema (instead of a schema that has to contain many possible node names). It will handle different grouping possibilities more naturally, and it will take care of all the XML weirdness that FOR XML handles behind the scenes.

                  也就是說,技術上可以實現你最初的愿望;這是一個可以做到的查詢:

                  That said, it is technically possible to achieve your original desire; here's a query that would do it:

                  SELECT 
                      CAST('<' + RptType + '>'
                      + (SELECT 
                          '<' + DataType + '>' 
                          + (SELECT
                              '<' + Branch + '>'
                              + REPLACE(REPLACE(
                              (SELECT
                                   '#' + acc + '!' as '*' , Actual, '#/' + acc + '!' as '*'
                                  FROM @t t4 WHERE t4.Branch = t3.Branch AND t4.DataType = t2.DataType AND t4.RptType = t1.RptType
                                  FOR XML PATH('')), '#', '<'), '!', '>')
                  
                              + '</' + Branch + '>'
                              FROM  @t t3  WHERE t3.DataType = t2.DataType AND t3.RptType = t1.RptType GROUP BY Branch)
                          + '</' + DataType + '>'
                          FROM @t t2  WHERE t2.RptType = t1.RptType GROUP BY DataType)
                      + '</' + RptType + '>'  AS XML)
                  FROM @t t1
                  GROUP BY RptType
                  

                  請注意,您不應該這樣做,這真的很丑陋(我只是向您展示,讓您了解即使參與其中也有多么丑陋).它真的只會變得更糟.我正在使用奇怪的字符串替換,可能會或可能不會在野外工作.最重要的是,如果任何節點具有無效的 XML 字符,則必須對其進行轉義 - 可能會添加一些額外的替換 (REPLACE(col, '<', '&lt;')) 或其他東西,但這又是丑陋的,并且必須對幾個值重復一遍.您基本上是將 SQL Server 用作 XML 編寫器,而實際上并不是要這樣做.如果你絕對必須有這個結構,那么你應該將數據傳遞給一個CLR類,該類可以正確使用XmlWriterXDocument之類的東西來編寫使用這些值的實際 XML.您甚至可以將 CLR 類放在 SQL Server 中并從存儲過程中調用它.

                  Note that you should not do this, it's really ugly hackery (I'm only showing you to give you an idea of how ugly even to get part of the way there). It really only gets worse. I'm using weird string replaces that may or may not work in the wild. On top of that, if any node has an invalid XML character, you'd have to escape it - maybe throw in some additional replaces (REPLACE(col, '<', '&lt;')) or something, but again that's ugly and has to be repeated all over for several values. You're basically using SQL Server as an XML Writer, and it's really not meant to do that. If you absolutely must have this structure, then you should pass the data to a CLR class that can properly use something like XmlWriter or XDocument to write the actual XML using these values. You could even put the CLR class in SQL Server and call it from the stored procedure.

                  這篇關于SQL 數據作為 XML 元素的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Can I figure out a list of databases and the space used by SQL Server instances without writing SQL queries?(我可以在不編寫 SQL 查詢的情況下找出數據庫列表和 SQL Server 實例使用的空間嗎?) - IT屋-程序員軟件開發
                  How to create a login to a SQL Server instance?(如何創建對 SQL Server 實例的登錄?)
                  How to know the version and edition of SQL Server through registry search(如何通過注冊表搜索知道SQL Server的版本和版本)
                  Why do I get a quot;data type conversion errorquot; with ExecuteNonQuery()?(為什么會出現“數據類型轉換錯誤?使用 ExecuteNonQuery()?)
                  How to show an image from a DataGridView to a PictureBox?(如何將 DataGridView 中的圖像顯示到 PictureBox?)
                  WinForms application design - moving documents from SQL Server to file storage(WinForms 應用程序設計——將文檔從 SQL Server 移動到文件存儲)

                        <bdo id='eC4Cq'></bdo><ul id='eC4Cq'></ul>
                      • <i id='eC4Cq'><tr id='eC4Cq'><dt id='eC4Cq'><q id='eC4Cq'><span id='eC4Cq'><b id='eC4Cq'><form id='eC4Cq'><ins id='eC4Cq'></ins><ul id='eC4Cq'></ul><sub id='eC4Cq'></sub></form><legend id='eC4Cq'></legend><bdo id='eC4Cq'><pre id='eC4Cq'><center id='eC4Cq'></center></pre></bdo></b><th id='eC4Cq'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='eC4Cq'><tfoot id='eC4Cq'></tfoot><dl id='eC4Cq'><fieldset id='eC4Cq'></fieldset></dl></div>

                          <legend id='eC4Cq'><style id='eC4Cq'><dir id='eC4Cq'><q id='eC4Cq'></q></dir></style></legend>
                              <tbody id='eC4Cq'></tbody>

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

                            <tfoot id='eC4Cq'></tfoot>
                            主站蜘蛛池模板: 一级毛片在线视频 | 亚洲444kkkk在线观看最新 | 精一区二区 | 精久久久久 | 成人av一区 | 91精品国产综合久久福利软件 | 国产亚洲精品精品国产亚洲综合 | 日韩欧美在线免费观看 | 岛国毛片| 中文字幕av网 | av在线一区二区三区 | 99国产精品视频免费观看一公开 | 成人影院在线 | 久色 | 亚洲精品视频在线 | 一区二区三区在线电影 | 国产精品网址 | 中文字幕乱码一区二区三区 | 91在线看网站 | 91在线影院 | 中文字幕一区二区三区四区五区 | 亚洲高清在线 | 久婷婷 | 亚洲欧美中文日韩在线v日本 | 亚洲国产中文字幕 | 欧美精品国产一区二区 | 久久久成人精品 | 欧美自拍一区 | 羞羞色影院| 免费黄色的视频 | 日本一区二区高清视频 | av在线免费不卡 | 欧美日韩精品中文字幕 | 国产福利资源在线 | 成人1区2区 | 国产97色| 久久久久久九九九九九九 | 视频在线亚洲 | 欧美日韩中文国产一区发布 | 欧美精品一区二区三区在线播放 | 在线免费观看视频你懂的 |