我需要能够从SQL表生成以下XML。 属性名称是表或查询中列的名称。
<case>
<caseProperties>
<property name="URErbName">xxx</property>
</caseProperties>
<caseData>
<entity type="case" name="1" />
<entity type="life" name="1" parentEntity="case_1">
<attribute name="RISK_TYPES" value="LIFE" />
<attribute name="AGE" value="45" />
<attribute name="GENDER" value="Male" />
<attribute name="BMI" value="30" />
<attribute name="DIAB_INSULIN_INJECTION" value="Yes" />
<attribute name="DIAB_NO_FURTHER_TREATMENT" value="Yes" />
<attribute name="DIAB_PREGNANT_CURRENT" value="No" />
<attribute name="DIAB_RECENT_HBA1C_READING" value="7.1 - 7.5%" />
<attribute name="DIAB_TIME_CONDITION_DIAGNOSED" value="6 - 15 years ago" />
<attribute name="DIAB_TWO_YEARS_HOSPITAL" value="No" />
<attribute name="DIABETES_GLU_INTOL_HBS" value="No" />
<attribute name="DIABETES_HBA1C" value="Yes" />
<attribute name="DIABETES_OTHER_COMPLICATIONS" value="No" />
<attribute name="GESTATIONAL_DIABETES" value="No" />
<attribute name="DISCLOSURES" value="Diabetes" />
</entity>
</caseData>
</case>
答案 0 :(得分:0)
您可以使用
select * from table1 FOR XML AUTO
如果这不适用于您。您可以使用更多自定义方式
SELECT
UrErbName as "case/caseProperties/property",
...
FROM Customers
FOR XML PATH('Customer')
检查this link以获取更多信息。