I have a query like this:
SELECT
getdate()[createdon], 'www.google.com'[XMLNS],
Co.Country, IC.InterConnectionName as point,
SO.SOName[TSO], FD.GasDay, FD.CaptureDate,
CD.mwhentry AS entrymwh, CD.mwhexit AS exitmwh,
DS.State, (CD.MWHENTRY - CD.MWHEXIT) AS NETMWH,
(cd.mwhexit - cd.mwhexit) as NETMCH
FROM
TABLENAME
I want this to convert into xml as
<gas-flow created-on="2012/06/02T10:30:01Z"
xmlns="www.google.com">
<country>Austria</country>
<point>TSO4</point>
<tso>BOG</tso>
<gas-day>2012/06/02</gas-day>
<capture-date>2012/06/02T10:30:00Z</capture-date>
<state version="1">provisional</state>
<entry mwh="558234" mcm="52.80"/>
<exit mwh="0" mcm="0"/>
<net mwh="558234" mcm="52.80"/>
</gas-flow>
If I do this with
FOR XML RAW ('gasflow'), ROOT ('FLOWDATAID'), ELEMENTS
I get also data between the tags but the problem is the values for the
entry tag, exit tag and net mwh
has to be like this
Thanks for the help..
You need to check out the
FOR XML PATH()syntax – it’s much more flexible thanFOR XML RAWand allows you to do things like specify certain output to be attributes (rather than elements).So try something like this: