TSQL for xml xml-tag 只需一次 [英] TSQL for xml xml-tag just once
本文介绍了TSQL for xml xml-tag 只需一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下 SELECT 查询:
I've the following SELECT Query:
SELECT
'2012' 'period',
Person.Name 'users/person'
FROM Person
FOR XML PATH(''), ROOT ('company')
这给了我以下 XML:
this gives me the following XML:
<company>
<period>2012</period>
<users>
<person>Dubach</person>
</users>
<period>2012</period>
<users>
<person>Pletscher</person>
</users>
<period>2012</period>
....
我希望在结果 XML 的开头只有一次句点"标签.我怎样才能做到这一点?
I would like to have the "period"-tag just once at the beginning of the result XML. how can I achieve this?
推荐答案
DECLARE @period XML = '<period>2012</period>'
DECLARE @xml XML = (
SELECT
Person.Name 'users/person'
FROM Person
FOR XML PATH(''), ROOT ('company')
)
SET @xml.modify('insert sql:variable("@period") as first into (/company)[1]')
SELECT @xml
这篇关于TSQL for xml xml-tag 只需一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文