我想将SQL Server 2012查询结果转换为格式化的XML结果。 我通常使用Visual Basic循环记录集并形成它。从SQL查询结果输出多级XML
查询是:
SELECT top 3
Plant_Devices.DeviceNumber, Plant_Devices.DeviceName,
SYS_Templates.TemplateTag, Plant_Alarms_Groups.GroupTag
FROM
Plant_Devices
INNER JOIN
SYS_Templates ON Plant_Devices.SYS_Templates_CID = SYS_Templates.CID
INNER JOIN
Plant_Alarms_Groups ON Plant_Devices.Plant_Alarms_Groups_CID = Plant_Alarms_Groups.CID
AND Plant_Devices.Plant_Alarms_Groups_CID = Plant_Alarms_Groups.CID
的结果是:
DeviceNumber DeviceName TemplateTag GroupTag
1 Stucco & Dry Add. D/C Fan D_Motor_Standard WM1_StuccoSys
10 Kiln Drive D_Drive_Standard WM1_KilnSys
118 HRA Feeder Agitator #1 D_Motor_Standard WM1_DryAdditives
所需的XML输出是:
<Tags>
<Tag name="1" path="" type="UDT_INST">
<Property name="Documentation" type="String">Stucco & Dry Add. D/C Fan</Property>
<Property name="DataType">2</Property>
<Property name="UDTParentType">D_Motor_Standard</Property>
<Parameters>
<Property name="AlarmGroup" type="String">WM1_StuccoSys</Property>
<Property name="DisplayName" type="String">1</Property>
<Property name="ID" type="String">1</Property>
</Parameters>
</Tag>
<Tag name="10" path="" type="UDT_INST">
<Property name="Documentation" type="String">Kiln Drive</Property>
<Property name="DataType">2</Property>
<Property name="UDTParentType">D_Drive_Standard</Property>
<Parameters>
<Property name="AlarmGroup" type="String">WM1_KilnSys</Property>
<Property name="DisplayName" type="String">10</Property>
<Property name="ID" type="String">10</Property>
</Parameters>
<Tag name="118" path="" type="UDT_INST">
<Property name="Documentation" type="String">HRA Feeder Agitator #1</Property>
<Property name="DataType">2</Property>
<Property name="UDTParentType">D_Motor_Standard</Property>
<Parameters>
<Property name="AlarmGroup" type="String">WM1_DryAdditives</Property>
<Property name="DisplayName" type="String">118</Property>
<Property name="ID" type="String">118</Property>
</Parameters>
</Tag>
</Tag>
</Tags>
谢谢!
欢迎堆栈溢出。您可能会发现,您需要更具体地确定您希望达到最终结果的准确程度。你想再次使用VB脚本吗?或者你正在寻找另一种解决方案?我真的不能在这里看到一个问题,它看起来更像是一个对我来说这样做。 –
我一直在尝试使用SQL Server中的xml生成器来输出所需的XML。但我似乎无法获得第二和第三级分支的输出。 –