Search
Submit & Win
Submit and win
Cash Prizes !
Winners

Win Prizes

Social Presence
Twitter Twitter LinkedIn YouTube Google

Like us on Facebook
Advertisements
Top Articles Author
Mon, 22-Dec-2014 Authors
All Time Authors
Vishal@Neeraj
43920
Rajkatie
20680
Bharathi Cherukuri
18040

Latest members | More ...


(Statistics delayed by 5 minutes)
 Interview Question

What is OPENXML in SQL Server?

 Posted by Raja on 12/14/2008 | Category: Sql Server Interview questions | Views: 15684

Answer:

OPENXML can parse the xml data in SQL server very efficiently in SQL Server. OpenXML primarily gives the ability to insert XML data to the relational database, however we can query the data too using OpenXML. We need to specify the path of the xml element using xpath.

Syntax:

DECLARE @index int

DECLARE @xmlString varchar(8000)
SET @xmlString ='<Persons>
<Person id="1">
<Name>Mohan</Name>
<PhoneNo>34343</PhoneNo>
</Person>
<Person id="2">
<Name>Sita</Name>
<PhoneNo>23432</PhoneNo>
</Person>
</Persons>'

EXEC sp_xml_preparedocument @index OUTPUT, @xmlString

SELECT *
FROM OPENXML (@index, 'Persons/Person')
WITH (id Varchar(10), Name varchar(100) 'Name' , PhoneNo Varchar(50) 'PhoneNo')

EXEC sp_xml_removedocument @index


The above code snippet will give following result.
---------------------------------
1 Mohan 34343
2 Sita 23432
---------------------------------


Asked In: Many Interviews | Alert Moderator 

Share this to:

Bookmark It

Comments or Responses

Login to post response