I have a XML file stored in a XML
datatype column data
in my table records
.
The table looks like this:
create table records
(
id int,
type nvarchar(28),
data xml,
posted datetime
)
XML data:
<Properties>
<data>
<Name>novel</Name>
<Gender>Female</Gender>
<Age>32</Age>
<Salary>55k</Salary>
<Phone>123-123</Phone>
</data>
</Properties>
I am currently using following query to extract data from that XML column which is taking more than minutes in 20K records.
select
id,
posteddate,
CONVERT( NVARCHAR(500), data.query('data(Properties/data/Name)') ) AS Name,
CONVERT( NVARCHAR(500), data.query('data(Properties/data/Gender)') ) AS Gender,
CONVERT( NVARCHAR(500), data.query('data(Properties/data/Age)') ) AS Age,
CONVERT( NVARCHAR(500), data.query('data(Properties/data/Salary)') ) AS Salary,
CONVERT( NVARCHAR(500), data.query('data(Properties/data/Phone)') ) AS Phone
from
records
where
type = 'personnel_xml'
Can anybody help explain how can I optimize this scenario as I need to extract 100 such elements from my XML stored as a column.