 




<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: get the value from XML in a sql table</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/get-the-value-from-xml-in-a-sql-table/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/get-the-value-from-xml-in-a-sql-table/</link>
	<description></description>
	<lastBuildDate>Sat, 18 May 2013 14:11:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: walrum</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/get-the-value-from-xml-in-a-sql-table/#comment-101970</link>
		<dc:creator>walrum</dc:creator>
		<pubDate>Tue, 24 Jan 2012 01:06:38 +0000</pubDate>
		<guid isPermaLink="false">#comment-101970</guid>
		<description><![CDATA[I’m not sure that I properly understand your question however below is the sample that perhaps can help you to understand the process of retrieving data from XML using SQL Statement. This sample is actually from Books Online and I believe that you should dig deeper in BO in order to use that and other statements. 
Here you are:
-- Create tables for later population using OPENXML.
CREATE TABLE Customers (CustomerID varchar(20) primary key,
                ContactName varchar(20), 
                CompanyName varchar(20))
GO
CREATE TABLE Orders( CustomerID varchar(20), OrderDate datetime)
GO
DECLARE @docHandle int
DECLARE @xmlDocument nvarchar(max) -- or xml type
SET @xmlDocument = N&#039;&lt;ROOT&gt;
&lt;Customers CustomerID=&quot;XYZAA&quot; ContactName=&quot;Joe&quot; CompanyName=&quot;Company1&quot;&gt;
&lt;Orders CustomerID=&quot;XYZAA&quot; OrderDate=&quot;2000-08-25T00:00:00&quot;/&gt;
&lt;Orders CustomerID=&quot;XYZAA&quot; OrderDate=&quot;2000-10-03T00:00:00&quot;/&gt;
&lt;/Customers&gt;
&lt;Customers CustomerID=&quot;XYZBB&quot; ContactName=&quot;Steve&quot;
CompanyName=&quot;Company2&quot;&gt;No Orders yet!
&lt;/Customers&gt;
&lt;/ROOT&gt;&#039;
EXEC sp_xml_preparedocument @docHandle OUTPUT, @xmlDocument
-- Use OPENXML to provide rowset consisting of customer data.
INSERT Customers 
SELECT * 
FROM OPENXML(@docHandle, N&#039;/ROOT/Customers&#039;) 
  WITH Customers
-- Use OPENXML to provide rowset consisting of order data.
INSERT Orders 
SELECT * 
FROM OPENXML(@docHandle, N&#039;//Orders&#039;) 
  WITH Orders
-- Using OPENXML in a SELECT statement.
SELECT * FROM OPENXML(@docHandle, N&#039;/ROOT/Customers/Orders&#039;) WITH (CustomerID nchar(5) &#039;../@CustomerID&#039;, OrderDate datetime)
-- Remove the internal representation of the XML document.
EXEC sp_xml_removedocument @docHandle 

If you will understand that sample I believe that getting more option should not create any problem]]></description>
		<content:encoded><![CDATA[<p>I’m not sure that I properly understand your question however below is the sample that perhaps can help you to understand the process of retrieving data from XML using SQL Statement. This sample is actually from Books Online and I believe that you should dig deeper in BO in order to use that and other statements.<br />
Here you are:<br />
&#8211; Create tables for later population using OPENXML.<br />
CREATE TABLE Customers (CustomerID varchar(20) primary key,<br />
                ContactName varchar(20),<br />
                CompanyName varchar(20))<br />
GO<br />
CREATE TABLE Orders( CustomerID varchar(20), OrderDate datetime)<br />
GO<br />
DECLARE @docHandle int<br />
DECLARE @xmlDocument nvarchar(max) &#8212; or xml type<br />
SET @xmlDocument = N&#8217;&lt;ROOT&gt;<br />
&lt;Customers CustomerID=&#8221;XYZAA&#8221; ContactName=&#8221;Joe&#8221; CompanyName=&#8221;Company1&#8243;&gt;<br />
&lt;Orders CustomerID=&#8221;XYZAA&#8221; OrderDate=&#8221;2000-08-25T00:00:00&#8243;/&gt;<br />
&lt;Orders CustomerID=&#8221;XYZAA&#8221; OrderDate=&#8221;2000-10-03T00:00:00&#8243;/&gt;<br />
&lt;/Customers&gt;<br />
&lt;Customers CustomerID=&#8221;XYZBB&#8221; ContactName=&#8221;Steve&#8221;<br />
CompanyName=&#8221;Company2&#8243;&gt;No Orders yet!<br />
&lt;/Customers&gt;<br />
&lt;/ROOT&gt;&#8217;<br />
EXEC sp_xml_preparedocument @docHandle OUTPUT, @xmlDocument<br />
&#8211; Use OPENXML to provide rowset consisting of customer data.<br />
INSERT Customers<br />
SELECT *<br />
FROM OPENXML(@docHandle, N&#8217;/ROOT/Customers&#8217;)<br />
  WITH Customers<br />
&#8211; Use OPENXML to provide rowset consisting of order data.<br />
INSERT Orders<br />
SELECT *<br />
FROM OPENXML(@docHandle, N&#8217;//Orders&#8217;)<br />
  WITH Orders<br />
&#8211; Using OPENXML in a SELECT statement.<br />
SELECT * FROM OPENXML(@docHandle, N&#8217;/ROOT/Customers/Orders&#8217;) WITH (CustomerID nchar(5) &#8216;../@CustomerID&#8217;, OrderDate datetime)<br />
&#8211; Remove the internal representation of the XML document.<br />
EXEC sp_xml_removedocument @docHandle </p>
<p>If you will understand that sample I believe that getting more option should not create any problem</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 6/9 queries in 0.013 seconds using memcached
Object Caching 268/271 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-18 14:55:51 -->