query attributes in XML object

  • i have an xml :

    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

  • SELECT r.value('@EMAIL','VARCHAR(30)') AS EMAIL,

    r.value('@PHONE','VARCHAR(30)') AS PHONE

    FROM @xml.nodes('/P/REC_LIST/REC') AS x(r)

    ____________________________________________________

    Deja View - The strange feeling that somewhere, sometime you've optimised this query before

    How to get the best help on a forum

    http://www.sqlservercentral.com/articles/Best+Practices/61537

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply