Link to home
Start Free TrialLog in
Avatar of soozh
soozhFlag for Sweden

asked on

SQL statement to produced xml of table

i am trying to produce an xml from a table and i am having trouble when trying to include column values as child nodes.

The table has many columns but I am having trouble with four columns that have to be nested in a child node.  These are the columns and they are all of type bit.

They are:

[RiskInflam]
[Vascularisation]
[Glaucoma]
[RiskAnnan]

I need to produce the xml in the format
<RiskFactors>
  <RiskFactor></RiskFactor>
</RiskFactors>

So when the row has the following values:

[RiskInflam]            1
[Vascularisation]      0
[Glaucoma]            1
[RiskAnnan]             0

I need to produce:
<RiskFactors>
  <RiskFactor>RF_RiskInflam</RiskFactor>
  <RiskFactor>RF_Glaucoma</RiskFactor>
</RiskFactors>

This is embedded in an xml document with other columns.

<LS2ECCTR xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Version>1</Version>
<LS-ID>1234567890</LS-ID>
…. Risk factors…..
</LS2ECCTR>

I am not sure of the sql/xml syntax to produce this.  Can anyone help?
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of soozh

ASKER

Very interesting solution.  I have now solved it another way but i like what you have done.

Thanks.