July 14, 2011 at 5:41 pm
I have an XML file in the following format and want to import it into the following table. How do I do this?
CREATE TABLE LookupTable (TableName varchar(128), ColumnName varchar(128), LookupValue varchar(255))
<?xml version="1.0" encoding="UTF-8">
<lookupsEntry table="L_RACETYPES">
<value column="RACETYPE">6</value>
<value column="RACECODE">0</value>
<value column="RACEDESC">Other than listed race</value>
<value column="RACERANK" />
</lookupsEntry>
July 15, 2011 at 3:06 am
Something like this?
SELECT
T.c.value('@table[1]','VARCHAR(30)') as TableName,
U.v.value('@column[1]','VARCHAR(30)') as ColumnName,
U.v.value('.[1]','VARCHAR(30)') as LookupValue
FROM @xml.nodes('lookupsEntry') T(c)
CROSS APPLY T.c.nodes('value') U(v)
July 15, 2011 at 8:55 am
You rock! That worked perfectly.
Thank you.
July 15, 2011 at 9:21 am
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy