I have the following query the runs very slowly. The sample below is just a few XML records. The actual data contains ~11,000 records and takes ~13 minutes to execute. Surely, I'm doing something wrong here. I seek guidance on how to speed up my query. TIA!
DECLARE @xml XML
SELECT @xml = '<output>
<record>
<field name="empid" id="empid" value="23" />
<field name="cbval" id="cbval" value="GD" />
</record>
<record>
<field name="empid" id="empid" value="23" />
<field name="cbval" id="cbval" value="MA" />
</record>
<record>
<field name="empid" id="empid" value="26" />
<field name="cbval" id="cbval" value="RV" />
</record>
<record>
<field name="empid" id="empid" value="78" />
<field name="cbval" id="cbval" value="BR" />
</record>
<record>
<field name="empid" id="empid" value="78" />
<field name="cbval" id="cbval" value="TX" />
</record>
</output>'
;
SELECT x.v.value('(field[@name="empid"]/@value)[1]', 'int'),
x.v.value('(field[@name="cbval"]/@value)[1]', 'varchar(50)')
FROM @xml.nodes('/output/record') x(v)
GO
Dave
[]
DECLARE @xml XML
SELECT @xml = '<output>
<record>
<field name="empid" id="empid" value="23" />
<field name="cbval" id="cbval" value="GD" />
</record>
<record>
<field name="empid" id="empid" value="23" />
<field name="cbval" id="cbval" value="MA" />
</record>
<record>
<field name="empid" id="empid" value="26" />
<field name="cbval" id="cbval" value="RV" />
</record>
<record>
<field name="empid" id="empid" value="78" />
<field name="cbval" id="cbval" value="BR" />
</record>
<record>
<field name="empid" id="empid" value="78" />
<field name="cbval" id="cbval" value="TX" />
</record>
</output>'
;
SELECT x.v.value('(field[@name="empid"]/@value)[1]', 'int'),
x.v.value('(field[@name="cbval"]/@value)[1]', 'varchar(50)')
FROM @xml.nodes('/output/record') x(v)
GO
Dave
[]