Мне нужно вернуть 2 строки данных из приведенного ниже XML.
| FaultText | Question1 | Question2 | Question3 | SOR |
|---------------------------|-----------------------|-------------------------|-----------|--------|
| Heating: radiator leaking | Q1 = Rad leaking? Yes | Q2 = Where? Bedroom | Null | HEA033 |
| Heating: radiator leaking | Q1 = Rad leaking? Yes | Q2 = Where? Living room | Null | HEA033 |
XML
<KeyfaxData>
<Fault name="Fault1" type="RD">
<FaultText>Heating: radiator leaking</FaultText>
<TenantID>123456</TenantID>
<TenantText>Mrs Bean</TenantText>
<UserCode>MBEAN</UserCode>
<ScriptPath>
<Question>Q1 = Rad leaking? Yes</Question>
<Question>Q2 = Where? Bedroom</Question>
</ScriptPath>
<Repair name="Repair1">
<RepairCodeEx>HEA033</RepairCodeEx>
<RepairCodeDesc>HEATING SYSTEM:REPAIR LEAK</RepairCodeDesc>
</Repair>
</Fault>
<Fault name="Fault2" type="RD">
<FaultText>Heating: radiator leaking</FaultText>
<TenantID>123457</TenantID>
<TenantText>Mrs Bean</TenantText>
<UserCode>MBEAN1</UserCode>
<ScriptPath>
<Question>Q1 = Rad leaking? Yes</Question>
<Question>Q2 = Where? Living room</Question>
</ScriptPath>
<Repair name="Repair1">
<RepairCodeEx>HEA033</RepairCodeEx>
<RepairCodeDesc>HEATING SYSTEM:REPAIR LEAK</RepairCodeDesc>
</Repair>
</Fault>
<GUID>AA9F632B-8F68-4D30-A954B40517C01947</GUID>
<Status>1</Status>
</KeyfaxData>
SQL, использованный до поиска имени ошибки, приведен ниже.Результаты этого показывают вопрос 1 ошибки 2 внутри вопроса 3.
SELECT
exportxml.value('(/KeyfaxData/Fault/FaultText)[1]','nvarchar(500)') as FaultText,
exportxml.value('(/KeyfaxData/Fault/ScriptPath/Question)[1]','nvarchar(500)') as Question1,
exportxml.value('(/KeyfaxData/Fault/ScriptPath/Question)[2]','nvarchar(500)') as Question2,
exportxml.value('(/KeyfaxData/Fault/ScriptPath/Question)[3]','nvarchar(500)') as Question3,
exportxml.value('(/KeyfaxData/Fault/Repair/RepairCode)[1]','nvarchar(500)') as SOR,
FROM KeyFaxHistory
Любая помощь будет высоко ценится!Я раньше не делал XQuery.