Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 query attributes in XML object

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2010-09-16 : 08:27:37
i have an xml :
quote:

Declare @xml as xml
set @xml='
<P>
<REC_LIST>
<REC EMAIL="aaa@some.com" PHONE="2222231000" />
<REC EMAIL="aaa@some.com" PHONE="1212121212" />
</REC_LIST>
</P>'


and i want to query the attributes from the @xml,something like :
select @xml.query(@email),@xml.query(@phone)

how do i do it?
thnaks




vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-09-16 : 10:24:09
try this -


Declare @xml as xml
set @xml='
<P>
<REC_LIST>
<REC EMAIL="aaa@some.com" PHONE="2222231000" />
<REC EMAIL="aaa@some.com" PHONE="1212121212" />
</REC_LIST>
</P>'

SELECT
b.value('@EMAIL', 'varchar(30)') AS EMAIL,
b.value('@PHONE', 'varchar(30)') AS PHONE
FROM @xml.nodes('/P') AS xmldata(fileds)
CROSS APPLY Fileds.nodes('REC_LIST/REC') AS a(b)



Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page
   

- Advertisement -