Monday, March 12, 2012

New problem getting data from xml table in sql db (Newbie)

Hello,

I have this xml tablerow in a table in my db.

2 examples

<Toyconfiguration version = "1" name = "Lego">

<Ballconfiguration version = "2020" name= "Adidas">

If I would want to get the name of the toy or ball I would write

Select

Tablerow.value('((@.name)[1]', 'varchar(100)')

From table

This would return Lego and Adidas

But what if I want to know which kind of configuration it is? How do I do this?

The answer I want is Toyconfiguration and Ballconfiguration..

Any help would be appreciated!

You could use local-name() function:

select

Tablerow.xml_col.value('(//@.name)[1]', 'varchar(100)')

,Tablerow.xml_col.value('local-name((*[@.name])[1])', 'varchar(100)')

from TableRow

|||

Kontantin,

Thanks a bunch for your answer. You saved me!!!

No comments:

Post a Comment