<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Coding Corner &#187; Select</title>
	<atom:link href="http://www.sres.co.uk/tag/select/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sres.co.uk</link>
	<description>Like a muller corner, mostly creamy yoghurt with a little bit of tasty stuff</description>
	<lastBuildDate>Tue, 30 Mar 2010 17:05:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Working with XML in SQL2008</title>
		<link>http://www.sres.co.uk/2009/08/25/working-with-xml-sql2008/</link>
		<comments>http://www.sres.co.uk/2009/08/25/working-with-xml-sql2008/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 13:56:05 +0000</pubDate>
		<dc:creator>Sres</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Insert]]></category>
		<category><![CDATA[Select]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL2008]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.sres.co.uk/?p=56</guid>
		<description><![CDATA[Since SQL2005 the ability to store entire XML documents within a database field has been achievable using the xml data type.  In this article I&#8217;m going to demonstrate how easy it is to create, store and retrieve an XML document from within SQL2008.
--Create a new table

CREATE TABLE BooksXML (
  BookID int PRIMARY KEY,
  [...]]]></description>
			<content:encoded><![CDATA[<p>Since SQL2005 the ability to store entire XML documents within a database field has been achievable using the xml data type.  In this article I&#8217;m going to demonstrate how easy it is to create, store and retrieve an XML document from within SQL2008.</p>
<pre class="brush:[sql]">--Create a new table

CREATE TABLE BooksXML (
  BookID int PRIMARY KEY,
  BookXml xml NOT NULL)</pre>
<p>Once the table has been created we need to add some basic information and insert it into the table.</p>
<pre class="brush:[sql]">--Insert two XML fragments

DECLARE @xml AS XML
SET @xml = '
<Books>
 <Book ID="1"
   BookTitle="Where Eagles Dare"
   BookAuthor="Alistair MacClean"
   BookCost="£9.99">
 </Book>
</Books>'

--insert into the table
INSERT INTO BooksXML (BookID, BookXml) VALUES (1, @xml)

SET @xml = '
<Books>
 <Book ID="2"
   BookTitle="Marker"
   BookAuthor="Robin Cook"
   BookCost="£8.99">
</Books>'

--insert into the table
INSERT INTO BooksXML (BookID, BookXml) VALUES (2, @xml)</pre>
<p>Your XML must be well formed when inserting into the database, any attempt to insert malformed XML will result in a regular XML error message.</p>
<p>Once we have stored the data, you will want to get at it again to display it.  If you want to find a specific book title you could use the exist function as below.</p>
<pre class="brush:[sql]">--Retrieve the book Marker by its name.

SELECT * FROM BooksXML
WHERE BookXml.exist('Books/Book[@name="Marker"]') = 1</pre>
<p>And that is it, you&#8217;ve stored XML, retrieved XML of a specific value, by delving into the XML stored within the SQL Server database.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sres.co.uk/2009/08/25/working-with-xml-sql2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
