March 11, 2011 at 10:07 am
Helllo,
Working in SQL 2008
Sample data from sql xml field (that is inserted into temp table #test)
<Listing xmlns="http://rets.org/xsd/Syndication/2008-03">
<Address>...
<ListPrice>327900</ListPrice>
Query I'm Using to Grab "ListPrice"
Select
p.value('/Listing[1]/@ListPrice[1]', 'varchar (100)')As ListPrice
FROM #test CROSS APPLY ListingNode.nodes('/Listing[1]/@ListPrice[1]') t(p)
Problem:
I'm not getting any results. Any thoughts on what I'm doing wrong?
Thanks, GA
March 11, 2011 at 10:57 am
A couple problems. You have a default namespace which you need to declare. I prefer using the "with xmlnamespaces" statement. Next, you are looking for a ListPrice element not a ListPrice attribute. @ListPrice returns the ListPrice attribute of the Listing element. ListPrice (with no @ prefix) returns the ListPrice element.
declare @t table (ListingNode xml);
insert into @t values(
'<Listing xmlns="http://rets.org/xsd/Syndication/2008-03">
<ListPrice>327900</ListPrice>
</Listing>')
; with xmlnamespaces (default 'http://rets.org/xsd/Syndication/2008-03')
Select
p.value('/Listing[1]/ListPrice[1]', 'varchar (100)')As ListPrice
FROM @t tmp CROSS APPLY tmp.ListingNode.nodes('/Listing[1]/ListPrice[1]') t(p)
Russel Loski, MCSE Business Intelligence, Data Platform
March 11, 2011 at 11:04 am
Thank you so much Russell. Your comments/advice were spot on. Very much appreciated.
March 23, 2011 at 3:58 am
Thanks Dear .your solution is so much helpful.
---------------------------------
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply