<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0" xml:base="http://www.red-gate.com/MessageBoard/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>Red Gate forums: SQL Prompt code snippets</title>
 <link>http://www.red-gate.com/MessageBoard/</link>
 <description>Product Support and Discussion</description>
 <language>en</language>
 <copyright>Copyright Red Gate Software Ltd</copyright>
 <managingEditor>internalsupport@red-gate.com</managingEditor>
 <webMaster>internalsupport@red-gate.com</webMaster>
 <docs>http://blogs.law.harvard.edu/tech/rss</docs>
 <ttl>60</ttl>
 <lastBuildDate>Mon, 20 May 2013 05:41:52 GMT</lastBuildDate>
 <pubDate>Mon, 20 May 2013 05:41:52 GMT</pubDate>
 <image>
  <url>http://www.red-gate.com/messageboard/templates/subRed/images/logo_phpBB.gif</url>
  <title>Red Gate forums: SQL Prompt code snippets</title>
  <link>http://www.red-gate.com/MessageBoard/</link>
 </image>
 <item>
  <title>RE: DECLARE CURSOR</title>
  <link>http://www.red-gate.com/MessageBoard/viewtopic.php?p=57031#57031</link>
  <description>An alternative view might be that if one uses cursors so rarely as to need a snippit to remeber all the correct syntax that's a good thing.</description>
  <category>SQL Prompt code snippets</category>
  <comments>http://www.red-gate.com/MessageBoard/posting.php?mode=reply&amp;t=10942</comments>
  <dc:creator>datacentricity</dc:creator>
  <pubDate>Thu, 19 Jul 2012 08:02:49 GMT</pubDate>
  <guid isPermaLink="true">http://www.red-gate.com/MessageBoard/viewtopic.php?p=57031#57031</guid>
 </item>
 <item>
  <title>RE: Start date of the current month</title>
  <link>http://www.red-gate.com/MessageBoard/viewtopic.php?p=54155#54155</link>
  <description>Brian
&lt;br /&gt;

&lt;br /&gt;
If you're finding that you need to get the first of the month often then you could look at incorporating a Lookup table into your coide that consist of rows for each date that falls within a range that would cover the dates you'd expect to use for the next 5 yeras or so.  The table would include the Date, the first day of that month, the last day of that month as well as other Date related data that is often obtained using one of the t-sql date functions and or string functions.
&lt;br /&gt;

&lt;br /&gt;
I work in a date heavy industry in which our transactional table has hundreads of millions of rows.  More then %50 of the queries involved need to get the first day of whatever month/Year the date on the transaction falls within.  Instead of using some extensive combination of string and date functions I join to a date lookup table on the date and return from it that First day of the month value.    Its very handy to have.</description>
  <category>SQL Prompt code snippets</category>
  <comments>http://www.red-gate.com/MessageBoard/posting.php?mode=reply&amp;t=6692</comments>
  <dc:creator>EdCarden</dc:creator>
  <pubDate>Thu, 01 Mar 2012 17:49:37 GMT</pubDate>
  <guid isPermaLink="true">http://www.red-gate.com/MessageBoard/viewtopic.php?p=54155#54155</guid>
 </item>
 <item>
  <title>RE: DECLARE CURSOR</title>
  <link>http://www.red-gate.com/MessageBoard/viewtopic.php?p=54153#54153</link>
  <description>DO you use cursors enough that you would benefit from having a Cursor code snippet in SQL Prompt?  
&lt;br /&gt;

&lt;br /&gt;
Cursors are a necessary evil in SQL that more often then ot are heavily over used by traditional procedural/OOP developers.  There are valid scenarios for using cursors but they are far and few.  If your using cursors enough that having a predefined code snippet would be of benefit then you should look take some time to look at alternatives to cursor use.
&lt;br /&gt;

&lt;br /&gt;
BTW - I mean no offense with the above; just comenting on how you could help yourself improve things by avoiding excess cursor use.</description>
  <category>SQL Prompt code snippets</category>
  <comments>http://www.red-gate.com/MessageBoard/posting.php?mode=reply&amp;t=10942</comments>
  <dc:creator>EdCarden</dc:creator>
  <pubDate>Thu, 01 Mar 2012 17:43:34 GMT</pubDate>
  <guid isPermaLink="true">http://www.red-gate.com/MessageBoard/viewtopic.php?p=54153#54153</guid>
 </item>
 <item>
  <title>Code to find all Stored Procedures in SQL Server</title>
  <link>http://www.red-gate.com/MessageBoard/viewtopic.php?p=48935#48935</link>
  <description>Hi,
&lt;br /&gt;
Here is a simple code to find all ACTIVE Stored Procedures in SQL Server
&lt;br /&gt;

&lt;br /&gt;

&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;SELECT DISTINCT so.name
&lt;br /&gt;
FROM syscomments sc
&lt;br /&gt;
INNER JOIN sysobjects so ON sc.id=so.id&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;</description>
  <category>SQL Prompt code snippets</category>
  <comments>http://www.red-gate.com/MessageBoard/posting.php?mode=reply&amp;t=13522</comments>
  <dc:creator>paulxavierx</dc:creator>
  <pubDate>Fri, 03 Jun 2011 18:19:07 GMT</pubDate>
  <guid isPermaLink="true">http://www.red-gate.com/MessageBoard/viewtopic.php?p=48935#48935</guid>
 </item>
 <item>
  <title>Create a New SP with Informational Headers &amp;amp; TRY/CATCH Block</title>
  <link>http://www.red-gate.com/MessageBoard/viewtopic.php?p=43635#43635</link>
  <description>&lt;span style=&quot;font-weight: bold&quot;&gt;Snippet:&lt;/span&gt; csp
&lt;br /&gt;
&lt;span style=&quot;font-weight: bold&quot;&gt;Description:&lt;/span&gt; Create a new stored procedure with informational headers and a TRY/CATCH block.
&lt;br /&gt;
&lt;span style=&quot;font-weight: bold&quot;&gt;Code:&lt;/span&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;SET ANSI_NULLS ON
&lt;br /&gt;
GO
&lt;br /&gt;
SET QUOTED_IDENTIFIER ON
&lt;br /&gt;
GO
&lt;br /&gt;
-- =============================================
&lt;br /&gt;
-- Author&amp;#58;&amp;nbsp; &amp;nbsp; &amp;nbsp; A. Jackson
&lt;br /&gt;
-- Create date&amp;#58; 2010/&amp;lt;Create Month,,12&amp;gt;/&amp;lt;Create Day,,31&amp;gt;
&lt;br /&gt;
-- Description&amp;#58; &amp;lt;Description,,&amp;gt;
&lt;br /&gt;
--
&lt;br /&gt;
-- Modifications&amp;#58;
&lt;br /&gt;
-- Author&amp;#58;&amp;nbsp; &amp;nbsp; &amp;nbsp; 
&lt;br /&gt;
-- Date&amp;#58;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; YYYY/MM/DD
&lt;br /&gt;
-- Description&amp;#58; 
&lt;br /&gt;
--&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;#58; 
&lt;br /&gt;
-- =============================================
&lt;br /&gt;
CREATE PROCEDURE &amp;lt;Procedure_Name, sysname, ProcedureName&amp;gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; -- WITH ENCRYPTION, RECOMPILE, EXECUTE AS CALLER|SELF|OWNER| 'user_name'
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; -- @parameter_name AS scalar_data_type &amp;#40; = default_value &amp;#41;, ...
&lt;br /&gt;
AS
&lt;br /&gt;
BEGIN
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; BEGIN TRY
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -- SET NOCOUNT ON added to prevent extra result sets from
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -- interfering with SELECT statements.
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SET NOCOUNT ON;
&lt;br /&gt;

&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $CURSOR$
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; END TRY
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; BEGIN CATCH
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; EXEC &amp;#91;dbo&amp;#93;.&amp;#91;dba_Error_Handler&amp;#93; @isDynamicSQL = &amp;lt;Is this using Dynamic SQL?,bit,0&amp;gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; END CATCH 
&lt;br /&gt;
END
&lt;br /&gt;
GO&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;
&lt;br /&gt;

&lt;br /&gt;
Use CTLR+SHIFT+M to bring up a dialog box that let's you enter &amp;lt;these, values&amp;gt; quickly and easily.
&lt;br /&gt;

&lt;br /&gt;
Please see my blog entry &amp;quot;&lt;span style=&quot;text-decoration: underline&quot;&gt;&lt;a href=&quot;http://explorationsincode.blogspot.com/2010/07/way-to-handle-raised-errors-in-both.html&quot; target=&quot;_blank&quot; class=&quot;postlink&quot;&gt;A Way to Handle Raised Errors in Both Dynamic and Static SQL Code&lt;/a&gt;&lt;/span&gt;&amp;quot; for more information about [dba_Error_Handler].</description>
  <category>SQL Prompt code snippets</category>
  <comments>http://www.red-gate.com/MessageBoard/posting.php?mode=reply&amp;t=12088</comments>
  <dc:creator>AndrewJacksonZA</dc:creator>
  <pubDate>Wed, 03 Nov 2010 09:59:46 GMT</pubDate>
  <guid isPermaLink="true">http://www.red-gate.com/MessageBoard/viewtopic.php?p=43635#43635</guid>
 </item>
 <item>
  <title>Add A Column To A Table With ExtendedProperty</title>
  <link>http://www.red-gate.com/MessageBoard/viewtopic.php?p=41124#41124</link>
  <description>I use this snippet when I want to add a column to a table and want to add a blurb about this columns purpose. 
&lt;br /&gt;

&lt;br /&gt;
Getting into the habit of using the ExtendedProperty also allows me to use SQLDoc to create documentation. No brainer! &lt;img src=&quot;images/smiles/icon_wink.gif&quot; alt=&quot;Wink&quot; border=&quot;0&quot; /&gt;
&lt;br /&gt;

&lt;br /&gt;
USE &amp;lt;DatabaseName&amp;gt;
&lt;br /&gt;

&lt;br /&gt;
BEGIN TRANSACTION
&lt;br /&gt;
GO
&lt;br /&gt;
ALTER TABLE dbo.&amp;lt;TableName&amp;gt; ADD &amp;lt;ColumnName&amp;gt; &amp;lt;DataType&amp;gt; NULL 
&lt;br /&gt;
GO
&lt;br /&gt;
--The statement below allows you to add a description to the field 
&lt;br /&gt;
--you're adding so that you can use SQLDoc to generate documentation
&lt;br /&gt;
EXEC sp_addextendedproperty N'MS_Description',
&lt;br /&gt;
    N'&amp;lt;Description of the purpose of the column&amp;gt;',
&lt;br /&gt;
    'SCHEMA', N'dbo', 'TABLE', N'&amp;lt;TableName&amp;gt;', 'COLUMN', '&amp;lt;ColumnName&amp;gt;'
&lt;br /&gt;
GO
&lt;br /&gt;
COMMIT
&lt;br /&gt;
GO</description>
  <category>SQL Prompt code snippets</category>
  <comments>http://www.red-gate.com/MessageBoard/posting.php?mode=reply&amp;t=11426</comments>
  <dc:creator>aultmike</dc:creator>
  <pubDate>Tue, 13 Jul 2010 20:41:22 GMT</pubDate>
  <guid isPermaLink="true">http://www.red-gate.com/MessageBoard/viewtopic.php?p=41124#41124</guid>
 </item>
 <item>
  <title>FormatDate</title>
  <link>http://www.red-gate.com/MessageBoard/viewtopic.php?p=40130#40130</link>
  <description>Snippet name: fd
&lt;br /&gt;
Description: Format a date as YYYY-MM-DD
&lt;br /&gt;
Code:
&lt;br /&gt;
CONVERT(CHAR(10), &amp;lt;inDate, DateTime, GETDATE()&amp;gt;, 23) AS [Date]
&lt;br /&gt;

&lt;br /&gt;
Use Ctrl-Shift-M to populate the parameter.
&lt;br /&gt;
Defaults to GetDate()</description>
  <category>SQL Prompt code snippets</category>
  <comments>http://www.red-gate.com/MessageBoard/posting.php?mode=reply&amp;t=11152</comments>
  <dc:creator>Bill_Ross</dc:creator>
  <pubDate>Mon, 24 May 2010 14:39:05 GMT</pubDate>
  <guid isPermaLink="true">http://www.red-gate.com/MessageBoard/viewtopic.php?p=40130#40130</guid>
 </item>
 <item>
  <title>rownum</title>
  <link>http://www.red-gate.com/MessageBoard/viewtopic.php?p=39938#39938</link>
  <description>I love the Over Partition:
&lt;br /&gt;

&lt;br /&gt;
row_number() OVER ( Partition BY &amp;lt;foreignkey, varchar&amp;gt; order by &amp;lt;foreignkey,varchar&amp;gt; ) AS [Seq]
&lt;br /&gt;

&lt;br /&gt;
Ctrl-Shit-M to populate</description>
  <category>SQL Prompt code snippets</category>
  <comments>http://www.red-gate.com/MessageBoard/posting.php?mode=reply&amp;t=11098</comments>
  <dc:creator>Bill_Ross</dc:creator>
  <pubDate>Thu, 13 May 2010 13:16:55 GMT</pubDate>
  <guid isPermaLink="true">http://www.red-gate.com/MessageBoard/viewtopic.php?p=39938#39938</guid>
 </item>
 <item>
  <title>RE: My 5 cents tip (you might know it already, but just in case)</title>
  <link>http://www.red-gate.com/MessageBoard/viewtopic.php?p=39719#39719</link>
  <description>Thanks!!!</description>
  <category>SQL Prompt code snippets</category>
  <comments>http://www.red-gate.com/MessageBoard/posting.php?mode=reply&amp;t=9229</comments>
  <dc:creator>AndrewJacksonZA</dc:creator>
  <pubDate>Wed, 05 May 2010 11:19:41 GMT</pubDate>
  <guid isPermaLink="true">http://www.red-gate.com/MessageBoard/viewtopic.php?p=39719#39719</guid>
 </item>
 <item>
  <title>RE: DECLARE CURSOR</title>
  <link>http://www.red-gate.com/MessageBoard/viewtopic.php?p=39375#39375</link>
  <description>Thanks, no matter how many times I need to write cursor code, I always cut and paste an example to make sure I get it all. This snippet will be very helpful.</description>
  <category>SQL Prompt code snippets</category>
  <comments>http://www.red-gate.com/MessageBoard/posting.php?mode=reply&amp;t=10942</comments>
  <dc:creator>Giggles220</dc:creator>
  <pubDate>Mon, 19 Apr 2010 15:43:21 GMT</pubDate>
  <guid isPermaLink="true">http://www.red-gate.com/MessageBoard/viewtopic.php?p=39375#39375</guid>
 </item>
 <item>
  <title>DECLARE CURSOR</title>
  <link>http://www.red-gate.com/MessageBoard/viewtopic.php?p=39371#39371</link>
  <description>Hi, I was looking for a DECLARE CURSOR snippet but I couldn't find one, so I decided to create this basic one.
&lt;br /&gt;

&lt;br /&gt;
&lt;span style=&quot;color: blue&quot;&gt;DECLARE&lt;/span&gt; $&lt;span style=&quot;color: blue&quot;&gt;CURSOR&lt;/span&gt;$&lt;span style=&quot;color: green&quot;&gt;--@Variables&lt;/span&gt;
&lt;br /&gt;

&lt;br /&gt;
&lt;span style=&quot;color: blue&quot;&gt;DECLARE&lt;/span&gt; &lt;span style=&quot;color: green&quot;&gt;/*Cursor name*/&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;CURSOR&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue&quot;&gt;FOR&lt;/span&gt; &lt;span style=&quot;color: green&quot;&gt;/*Select Statement*/&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue&quot;&gt;OPEN&lt;/span&gt; &lt;span style=&quot;color: green&quot;&gt;/*Cursor Name*/&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue&quot;&gt;FETCH&lt;/span&gt; NEXT &lt;span style=&quot;color: blue&quot;&gt;FROM&lt;/span&gt; &lt;span style=&quot;color: green&quot;&gt;/*Cursor Name*/&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue&quot;&gt;INTO&lt;/span&gt; &lt;span style=&quot;color: green&quot;&gt;--@Variables&lt;/span&gt;
&lt;br /&gt;

&lt;br /&gt;
&lt;span style=&quot;color: blue&quot;&gt;WHILE&lt;/span&gt; &lt;span style=&quot;color: violet&quot;&gt;@@FETCH_STATUS&lt;/span&gt; = 0 
&lt;br /&gt;
    &lt;span style=&quot;color: blue&quot;&gt;BEGIN&lt;/span&gt;
&lt;br /&gt;
        
&lt;br /&gt;
        &lt;span style=&quot;color: green&quot;&gt;/*SQL Statements*/&lt;/span&gt;
&lt;br /&gt;
        
&lt;br /&gt;
        &lt;span style=&quot;color: blue&quot;&gt;FETCH&lt;/span&gt; NEXT &lt;span style=&quot;color: blue&quot;&gt;FROM&lt;/span&gt; &lt;span style=&quot;color: green&quot;&gt;/*Cursor Name*/&lt;/span&gt;
&lt;br /&gt;
		&lt;span style=&quot;color: blue&quot;&gt;INTO&lt;/span&gt; &lt;span style=&quot;color: green&quot;&gt;--@Variables&lt;/span&gt;	
&lt;br /&gt;
    &lt;span style=&quot;color: blue&quot;&gt;END&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue&quot;&gt;CLOSE&lt;/span&gt; &lt;span style=&quot;color: green&quot;&gt;/*Cursor Name*/&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue&quot;&gt;DEALLOCATE&lt;/span&gt; &lt;span style=&quot;color: green&quot;&gt;/*Cursor Name*/&lt;/span&gt;
&lt;br /&gt;

&lt;br /&gt;
I hope it helps!</description>
  <category>SQL Prompt code snippets</category>
  <comments>http://www.red-gate.com/MessageBoard/posting.php?mode=reply&amp;t=10942</comments>
  <dc:creator>aorozco</dc:creator>
  <pubDate>Mon, 19 Apr 2010 14:54:34 GMT</pubDate>
  <guid isPermaLink="true">http://www.red-gate.com/MessageBoard/viewtopic.php?p=39371#39371</guid>
 </item>
 <item>
  <title>RE: Extended TRY-CATCH block</title>
  <link>http://www.red-gate.com/MessageBoard/viewtopic.php?p=38186#38186</link>
  <description>Nice! Thx for sharing!</description>
  <category>SQL Prompt code snippets</category>
  <comments>http://www.red-gate.com/MessageBoard/posting.php?mode=reply&amp;t=10596</comments>
  <dc:creator>aultmike</dc:creator>
  <pubDate>Thu, 25 Feb 2010 18:57:15 GMT</pubDate>
  <guid isPermaLink="true">http://www.red-gate.com/MessageBoard/viewtopic.php?p=38186#38186</guid>
 </item>
 <item>
  <title>Extended TRY-CATCH block</title>
  <link>http://www.red-gate.com/MessageBoard/viewtopic.php?p=38169#38169</link>
  <description>Hi,
&lt;br /&gt;

&lt;br /&gt;
let me share this SQL block, which seems to be useful for proper error handling in stored procedures...
&lt;br /&gt;

&lt;br /&gt;
UPDATED: I found a defect in the original error handler (message was limited to 300 chars). Below is the refined version:
&lt;br /&gt;

&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;BEGIN TRY
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; BEGIN TRAN usp_procXXX
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; $CURSOR$--
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; COMMIT TRAN usp_procXXX
&lt;br /&gt;
END TRY
&lt;br /&gt;
BEGIN CATCH
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; DECLARE
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @ErrorMessage varchar&amp;#40;max&amp;#41;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; , @ErrorSeverity int
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; , @ErrorState int
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; SELECT @ErrorMessage =
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 'Error ' 
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; + CAST&amp;#40; ERROR_NUMBER&amp;#40;&amp;#41; as varchar &amp;#41; 
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; + ' &amp;quot;' + ERROR_MESSAGE&amp;#40;&amp;#41; + '&amp;quot; '
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; + 'raised in ' + ISNULL&amp;#40; ERROR_PROCEDURE&amp;#40;&amp;#41;, 'raw SQL' &amp;#41; 
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; + ' line ' + CAST&amp;#40;&amp;nbsp; ERROR_LINE&amp;#40;&amp;#41; as varchar &amp;#41; 
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; , @ErrorSeverity = ERROR_SEVERITY&amp;#40;&amp;#41;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; , @ErrorState = ERROR_STATE&amp;#40;&amp;#41;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; IF XACT_STATE&amp;#40;&amp;#41; &amp;lt;&amp;gt; 0
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; BEGIN
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IF @@TRANCOUNT &amp;gt; 0
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ROLLBACK TRANSACTION usp_procXXX;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; END
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; RAISERROR &amp;#40; @ErrorMessage, @ErrorSeverity, @ErrorState &amp;#41;
&lt;br /&gt;
END CATCH
&lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;</description>
  <category>SQL Prompt code snippets</category>
  <comments>http://www.red-gate.com/MessageBoard/posting.php?mode=reply&amp;t=10596</comments>
  <dc:creator>ENedelko</dc:creator>
  <pubDate>Thu, 25 Feb 2010 16:01:12 GMT</pubDate>
  <guid isPermaLink="true">http://www.red-gate.com/MessageBoard/viewtopic.php?p=38169#38169</guid>
 </item>
 <item>
  <title>RE: My 5 cents tip (you might know it already, but just in case)</title>
  <link>http://www.red-gate.com/MessageBoard/viewtopic.php?p=37164#37164</link>
  <description>Awesome tip!</description>
  <category>SQL Prompt code snippets</category>
  <comments>http://www.red-gate.com/MessageBoard/posting.php?mode=reply&amp;t=9229</comments>
  <dc:creator>aultmike</dc:creator>
  <pubDate>Tue, 19 Jan 2010 15:35:27 GMT</pubDate>
  <guid isPermaLink="true">http://www.red-gate.com/MessageBoard/viewtopic.php?p=37164#37164</guid>
 </item>
 <item>
  <title>My 5 cents tip (you might know it already, but just in case)</title>
  <link>http://www.red-gate.com/MessageBoard/viewtopic.php?p=33368#33368</link>
  <description>I like to combine the SQL Prompt code snippets with the SQL Server Management Studio templates. I always liked the template (kind of the same idea of snippets) but SSMS lacks the ability of &amp;quot;calling&amp;quot; those templates right from your query window. I mean, you must go to the Template Collection, find the needed template and from there double click on it or drag and drop.
&lt;br /&gt;

&lt;br /&gt;
So, now what I do? I just create snippets using the template format. For example:
&lt;br /&gt;

&lt;br /&gt;
USE &amp;lt;Database, varchar,&amp;gt;
&lt;br /&gt;
go
&lt;br /&gt;

&lt;br /&gt;
select * from &amp;lt;Table, varchar,&amp;gt;
&lt;br /&gt;
go
&lt;br /&gt;

&lt;br /&gt;
Once I call it, I press CTRL+SHIFT+M and the template parameter window will show up allowing me to enter the defined paramaters of the current template.
&lt;br /&gt;

&lt;br /&gt;
Hope this will help someone &lt;img src=&quot;images/smiles/icon_smile.gif&quot; alt=&quot;Smile&quot; border=&quot;0&quot; /&gt;</description>
  <category>SQL Prompt code snippets</category>
  <comments>http://www.red-gate.com/MessageBoard/posting.php?mode=reply&amp;t=9229</comments>
  <dc:creator>ivanrdgz</dc:creator>
  <pubDate>Sat, 11 Jul 2009 04:26:04 GMT</pubDate>
  <guid isPermaLink="true">http://www.red-gate.com/MessageBoard/viewtopic.php?p=33368#33368</guid>
 </item>
</channel>
</rss>
