Avatar of crompnk
Flag for United Kingdom of Great Britain and Northern Ireland asked on

parsing xml using tsql


I am trying to parse a snippet of xml using the following tsql. It is working without errors but I am getting null data rather than the values in double quotes:


SET @x = '
<TH date="20150730133052" id="th0" temp="21.9" hum="61" dew="14.0"/>
<WIND date="20150730133114" id="wind0" dir="0" gust="0.0" wind="0.0" chill="21.9"/>
<RAIN date="20150730133016" id="rain0" rate="0.0" total="0.0" delta="0.0"/>
<THB date="20150730133040" id="thb0" temp="24.0" hum="53" dew="13.8" press="1021.7" seapress="1022.0" fc="2"/>

SELECT tbl.TH.value('date[1]', 'varchar(100)') AS [date]
	,tbl.TH.value('id[1]', 'varchar(100)') AS id
	,tbl.TH.value('temp[1]', 'varchar(100)') AS temp
	,tbl.TH.value('hum[1]', 'varchar(100)') AS hum
	,tbl.TH.value('dew[1]', 'varchar(100)') AS dew
FROM @x.nodes('/logger/TH') AS tbl(TH);

Open in new window

Thank you
Microsoft SQL Server 2008

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy