久久久久久久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 數(shù)據(jù)作為 XML 元素

        SQL Data as XML Element(SQL 數(shù)據(jù)作為 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 數(shù)據(jù)作為 XML 元素的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時(shí)送ChatGPT賬號(hào)..

                  我對(duì)用 SQL 生成 XML 有點(diǎn)陌生.我正在嘗試從此查詢生成 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
                  

                  查詢產(chǎn)生以下結(jié)果:

                  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 列中的查詢結(jié)果實(shí)際用作 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>
                  

                  有人能指出我正確的方向嗎?我應(yīng)該使用 T-SQL 并遍歷查詢結(jié)果以制作 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?

                  感謝您的幫助!

                  推薦答案

                  這在技術(shù)上是可行的,但由于一些原因,它確實(shí)很糟糕.相反,您應(yīng)該重新考慮您的 XML 結(jié)構(gòu),使其更像這樣:

                  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');
                  

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

                  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.

                  也就是說,技術(shù)上可以實(shí)現(xiàn)你最初的愿望;這是一個(gè)可以做到的查詢:

                  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
                  

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

                  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.

                  這篇關(guān)于SQL 數(shù)據(jù)作為 XML 元素的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Can I figure out a list of databases and the space used by SQL Server instances without writing SQL queries?(我可以在不編寫 SQL 查詢的情況下找出數(shù)據(jù)庫列表和 SQL Server 實(shí)例使用的空間嗎?) - IT屋-程序員軟件開發(fā)
                  How to create a login to a SQL Server instance?(如何創(chuàng)建對(duì) SQL Server 實(shí)例的登錄?)
                  How to know the version and edition of SQL Server through registry search(如何通過注冊(cè)表搜索知道SQL Server的版本和版本)
                  Why do I get a quot;data type conversion errorquot; with ExecuteNonQuery()?(為什么會(huì)出現(xiàn)“數(shù)據(jù)類型轉(zhuǎn)換錯(cuò)誤?使用 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 應(yīng)用程序設(shè)計(jì)——將文檔從 SQL Server 移動(dòng)到文件存儲(chǔ))

                        <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>
                            主站蜘蛛池模板: 男人的天堂中文字幕 | 成人精品区 | 日本aⅴ中文字幕 | 在线观看免费av网 | 一级黄色片在线看 | 99re在线视频 | 日韩美女一区二区三区在线观看 | 久久一二区 | 在线观看黄免费 | 超碰在线人人 | 日本免费小视频 | 亚洲欧美一区二区三区情侣bbw | 色www精品视频在线观看 | 久久亚洲欧美日韩精品专区 | 精品视频一区二区三区 | 国产在线a视频 | 国产成人精品午夜视频免费 | 日韩在线| 欧美性网 | 成人啊啊啊 | 男人天堂手机在线视频 | 97在线播放| 亚洲精品中文字幕av | 免费在线观看黄视频 | 久久久久成人精品 | 中文在线一区二区 | 91麻豆精品国产91久久久久久久久 | 91精品久久久久久久久久入口 | 国产1区 | 拍真实国产伦偷精品 | 天天操夜夜操 | 女生羞羞视频 | 精品日韩欧美一区二区 | 日日骚视频 | 欧美综合精品 | 亚洲国产高清高潮精品美女 | 自拍偷拍第一页 | 色播99| a级毛片毛片免费观看久潮喷 | 日韩午夜一区二区三区 | 午夜一区二区三区在线观看 |