We help IT Professionals succeed at work.
Get Started

parsing xml using tsql

crompnk asked
Last Modified: 2015-08-01

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
Watch Question
Senior Developer
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE