XML与标签之间的内容

时间:2013-06-05 20:19:21

标签: xml sql-server-2008 sqlxml

我有SQL

SELECT '' AS "dfn", CCFKeyType AS "dfn/b", GroupID AS "dfn/var",  ID AS "dfn/code"
FROM (
...
) A

FOR XML PATH('')

它生成

<dfn>
   <b>cid</b>
   <var>0115</var>
   <code>EXS</code>
</dfn>

我想生成:

<dfn>
   <b>cid</b>
   (<var>0115</var>):
   <code>EXS</code>
</dfn>

如何在标签之间插入文本数据?

1 个答案:

答案 0 :(得分:1)

SELECT  ''     AS "dfn"    , 
        'cid'  AS "dfn/b"  ,
        '('    AS "dfn"    ,
        '0115' AS "dfn/var",
        '):'   AS "dfn"    ,
        'EXS'  AS "dfn/code"
FOR XML PATH('')

输出:

<dfn>
    <b>cid</b>
    (<var>0115</var>):
    <code>EXS</code>
</dfn>