开发者

How to shape rename sql.xml query xml elements

I have the following query

insert @p(target,type,val,[order])
        select "/session/verbs/put[@field='orno.f']",'string',141527,1
union   select "/session/verbs/put[@field='orno.t']","string",141527,2
union   select "/session/verbs/put[@field='orno.t']","string",141527,2
union   select "/session/verbs/put[@field='comp.f']","string",000,2
union   select "/sess开发者_Python百科ion/verbs/put[@field='comp.t']","string",999,2.1
union   select "/session/verbs/setreport/parameter[@name='device']","string",105,3

set quoted_identifier on
SELECT  (SELECT target, type
         FROM @p

         FOR XML RAW, TYPE,ROOT('session')).query('/*');

and this returns

<session>
  <row target="/session/verbs/put[@field='comp.f']" type="string" />
  <row target="/session/verbs/put[@field='comp.t']" type="string" />
  <row target="/session/verbs/put[@field='orno.f']" type="string" />
  <row target="/session/verbs/put[@field='orno.t']" type="string" />
  <row target="/session/verbs/setreport/parameter[@name='device']" type="string" />

How can I modify the query to rename <row> to <parameter>


if you user SQL Server 2008 (R2) you may pass your parameter name after RAW derective:

FOR XML RAW('parameter'), TYPE,ROOT('session')).query('/*');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜