1

I want to get gid and uid from the below xml. This xml exists as a column in a SQL Server 2008 table called xmlmsg. I need a SQL query that parses the table which has an xml column with the data like below:

<person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns="http://api.money.com/schema/contact" Email="" 
        gId="11" uId="uadgra45678" Timestamp="2013-10-17T19:19:41Z" 
        xsi:schemaLocation="http://api.money.com/schema/contact http://api.money.com/schema/contact/contact-1.2.xsd">
</person>
1
  • Define parse. What is the expected output given this XML data? Commented Oct 10, 2014 at 0:46

1 Answer 1

1

(This is really a comment because it doesn't seem to answer the question implied by the title.)

This query (from LinqPad) creates and retrieves XML data:

--Drop Table #TempXml

Create Table #TempXml(Value XML)

Insert Into #TempXml(Value)Values('<person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://api.money.com/schema/contact" Email=""
        gId="11" uId="uadgra45678" Timestamp="2013-10-17T19:19:41Z"
        xsi:schemaLocation="http://api.money.com/schema/contact http://api.money.com/schema/contact/contact-1.2.xsd">
</person>')

Select count(*) from #TempXml;

Select * from #TempXml;

Select Value.value('declare namespace AMC="http://api.money.com/schema/contact";
/AMC:person[1]/@uId','varchar(max)')
,Value.value('declare namespace AMC="http://api.money.com/schema/contact";
/AMC:person[1]/@gId','int')
From #TempXml;

Drop Table #TempXml
Sign up to request clarification or add additional context in comments.

1 Comment

Here's a Stack Exchange Data Explorer query for the above snippet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.