2016-08-03 59 views
0

我已经包含个XML这样获取包含个XML

------ 
1. <xml><.....></xml> 
2. <xml><.....></xml> 
3. <xml><.....></xml> 
------ 

现在,我要的是具有含所有这些个XML一个XML表格@t_myTable一个表的XML。 我试图与此查询

SELECT myTable.Value 
FROM @t_myTable myTable 
FOR XML AUTO, ROOT ('XML')) 

但我得到的是大量的嵌套节点的XML来解决这个问题,这样我们

<XML>     <- the XML root as I want 
    <myTable>   <- the name of the Table, useless in my XML 
    <Value>   <- the name of the column, useless in my XML 
     <xml>   <- the xml that I want to append to ROOT Node 
     ....   <- ecc. ecc. 

所以我要问什么是我该怎么用最简单的方法来最小化xml中的节点,如下所示:

<XML> 
    <xml> 
    ....... 
    </xml> 
    <xml> 
    ....... 
    </xml> 
<XML> 

???预先感谢您的支持

回答

3

尝试像这样

DECLARE @tbl TABLE(xml XML); 
INSERT INTO @tbl VALUES 
('<xml><a>Some a value</a></xml>') 
,('<xml><a>Another a value</a></xml>') 
,('<xml><a>And one more a value</a></xml>'); 

SELECT xml AS [*] 
FROM @tbl 
FOR XML PATH(''),ROOT('xml') 

结果

<xml> 
    <xml> 
    <a>Some a value</a> 
    </xml> 
    <xml> 
    <a>Another a value</a> 
    </xml> 
    <xml> 
    <a>And one more a value</a> 
    </xml> 
</xml>