<?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>David Laing's blog &#187; MSSQL</title>
	<atom:link href="http://davidlaing.com/category/platforms/mssql/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidlaing.com</link>
	<description>Craftmanship over crap</description>
	<lastBuildDate>Mon, 19 Jul 2010 00:39:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9-rare</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Try/Catch for SQL!?</title>
		<link>http://davidlaing.com/2009/03/05/trycatch-for-sql/</link>
		<comments>http://davidlaing.com/2009/03/05/trycatch-for-sql/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 11:42:05 +0000</pubDate>
		<dc:creator>mrdavidlaing</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[MSSQL]]></category>

		<guid isPermaLink="false">http://davidlaing.com/?p=167</guid>
		<description><![CDATA[Thanks to Nick Sertis for this trick &#8211; who knew TSQL could do try/catch statements!
Very useful when you need to write data manipulation scripts for production databases.

[-]?View Code SQL1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
BEGIN TRY
&#160;
    BEGIN TRAN
&#160;
        --Some SQL
&#160;
&#160;
    COMMIT TRAN
&#160;
END TRY
-- Catch the errors on the [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to <a href="http://www.sertis.net" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://www.sertis.net');">Nick Sertis</a> for this trick &#8211; who knew TSQL could do try/catch statements!</p>
<p>Very useful when you need to write data manipulation scripts for production databases.</p>

<div id="wp_codebox_msgheader"><span class="right"><a href="javascript:;" onclick="toggle_collapse('p1672');">[<span id="p1672_symbol">-</span>]</a><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p167code2'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div id="wp_codebox"><table width="100%" ><tr id="p1672"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p167code2"><pre class="sql">BEGIN TRY
&nbsp;
    BEGIN TRAN
&nbsp;
        <span style="color: #808080; font-style: italic;">--Some SQL</span>
&nbsp;
&nbsp;
    COMMIT TRAN
&nbsp;
END TRY
<span style="color: #808080; font-style: italic;">-- Catch the errors on the inserts</span>
BEGIN CATCH
&nbsp;
    ROLLBACK TRAN
    <span style="color: #993333; font-weight: bold;">SELECT</span> ERROR_MESSAGE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
END CATCH</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://davidlaing.com/2009/03/05/trycatch-for-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
