2

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 "/session/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>

2
  • Why do you want to? Wouldn't it be easier to adjust the part that consumes the XML that the elements are called <row>? Commented Dec 18, 2010 at 12:29
  • @Tomolak this is just the begining, I will need to add many more child elemements to this.. it perhaps makes sense to refer /session/parameters/parameter /session/verbs/verb[@setreport]/parameter/... than /session/row/row.. etc.. Commented Dec 18, 2010 at 12:32

1 Answer 1

2

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

FOR XML RAW('parameter'), TYPE,ROOT('session')).query('/*');
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Aspirin, how is your blood thickness ?(:-

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.