<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 't-sql tuesday' and 'INFORMATION_SCHEMA'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=t-sql+tuesday,INFORMATION_SCHEMA&amp;orTags=0</link><description>Search results matching tags 't-sql tuesday' and 'INFORMATION_SCHEMA'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>T-SQL Tuesday #24 : Dude, where's the rest of my procedure?</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2011/11/08/t-sql-tuesday-24-dude-where-s-the-rest-of-my-procedure.aspx</link><pubDate>Tue, 08 Nov 2011 07:19:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:39648</guid><dc:creator>AaronBertrand</dc:creator><description>&lt;p&gt;&lt;a href="http://sqlserverpedia.com/blog/sql-server-bloggers/invitation-for-t-sql-tuesday-024-prox-%E2%80%98n%E2%80%99-funx/" title="http://sqlserverpedia.com/blog/sql-server-bloggers/invitation-for-t-sql-tuesday-024-prox-%E2%80%98n%E2%80%99-funx/" target="_blank"&gt;&lt;img src="http://sqlblog.com/files/folders/36686/download.aspx" style="padding:0px 30px 12px 30px;" align="right" border="0" height="99" width="99"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This month's &lt;a href="http://sqlserverpedia.com/blog/sql-server-bloggers/invitation-for-t-sql-tuesday-024-prox-%E2%80%98n%E2%80%99-funx/" title="http://sqlserverpedia.com/blog/sql-server-bloggers/invitation-for-t-sql-tuesday-024-prox-%E2%80%98n%E2%80%99-funx/" target="_blank"&gt;T-SQL Tuesday&lt;/a&gt; is being hosted by Brad Schulz (&lt;a href="http://bradsruminations.blogspot.com/" title="http://bradsruminations.blogspot.com/" target="_blank"&gt;blog&lt;/a&gt;) and the topic is one that should attract a lot of submissions: Procedures and Functions.
&lt;/p&gt;

&lt;p&gt;Last week, I talked about &lt;a href="http://sqlblog.com/blogs/aaron_bertrand/archive/2011/11/03/the-case-against-information-schema-views.aspx" title="http://sqlblog.com/blogs/aaron_bertrand/archive/2011/11/03/the-case-against-information-schema-views.aspx" target="_blank"&gt;the case against INFORMATION_SCHEMA views&lt;/a&gt; - I provided several examples where I feel the INFORMATION_SCHEMA views fall short of the catalog views, and expressed my belief that you are better off programming consistently against the catalog views all the time, instead of only when the INFORMATION_SCHEMA views fail. Having known at that time about the T-SQL Tuesday topic, I intentionally left one incriminating piece of evidence out of that discussion, and that is how INFORMATION_SCHEMA.ROUTINES feels about your procedures and functions that are longer than 4,000 characters (8,000 bytes).&lt;/p&gt;

&lt;p&gt;In SQL Server 2000, you had three ways to retrieve the definition of a procedure or function: INFORMATION_SCHEMA.ROUTINES, syscomments, and sp_helptext. The problem with sp_helptext is that you can't use it interactively - say you don't know the name of the procedure(s) you're trying to retrieve, but want to base it on a search of the text (e.g. return all the stored procedures that contain 'dbo.foo'). You could get there with either of the views, but in fact all three of these approaches have issues:&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;b&gt;INFORMATION_SCHEMA.ROUTINES&lt;/b&gt; only contains the first 4,000 characters of the procedure body. If your procedure is longer, and the text you're looking for falls outside of that (or even if you just want the whole procedure), you're going to be out of luck. This is because the definition of the view purposely truncates the definition:

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;...&lt;br&gt;&lt;font color="black"&gt;&lt;/font&gt;&lt;font color="magenta"&gt;convert&lt;/font&gt;&lt;font color="gray"&gt;(&lt;font color="blue"&gt;nvarchar&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;4000&lt;/font&gt;&lt;font color="gray"&gt;),&lt;br&gt;    &lt;/font&gt;&lt;font color="magenta"&gt;object_definition&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;o.&lt;/font&gt;&lt;font color="magenta"&gt;object_id&lt;/font&gt;&lt;font color="gray"&gt;))&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;ROUTINE_DEFINITION&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&lt;/font&gt;...
&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;


&lt;p&gt;I assume this truncation occurs so that the view still conforms to the standard - so even though your entire procedure body is available, it won't show you the whole thing.&lt;br&gt;&amp;nbsp;&lt;br&gt;&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;&lt;b&gt;syscomments&lt;/b&gt; is an odd bird, in that it chops your text up into 4,000-character chunks. So while you can manually piece your procedure definition back together (unlike INFORMATION_SCHEMA.ROUTINES, you can't rely on a search of the text for modules that are longer than 4,000 characters, because your search phrase may only occur in a location where it straddles two rows in the result. I'd dig into the mechanics behind this, but you can't get very far... while you can certainly run the following to see what the view does:

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;EXEC &lt;/font&gt;&lt;font color="darkred"&gt;sp_helptext &lt;/font&gt;&lt;font color="red"&gt;'sys.syscomments'&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

You can see that it references a system table, sys.sysschobjs, and internal functions like sysconv() and OPENROWSET(TABLE SQLSRC):

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;CREATE VIEW &lt;/font&gt;&lt;font color="green"&gt;sys.syscomments &lt;/font&gt;&lt;font color="blue"&gt;AS&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SELECT &lt;/font&gt;&lt;font color="black"&gt;o.id &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;id&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;convert&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;smallint&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="blue"&gt;case when &lt;/font&gt;&lt;font color="black"&gt;o.&lt;/font&gt;&lt;font color="blue"&gt;type &lt;/font&gt;&lt;font color="gray"&gt;in&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="red"&gt;'P'&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="red"&gt;'RF'&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="blue"&gt;then &lt;/font&gt;&lt;font color="black"&gt;1 &lt;/font&gt;&lt;font color="blue"&gt;else &lt;/font&gt;&lt;font color="black"&gt;0 &lt;/font&gt;&lt;font color="blue"&gt;end&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;number&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;s.colid&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;s.&lt;/font&gt;&lt;font color="blue"&gt;status&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;convert&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;varbinary&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;8000&lt;/font&gt;&lt;font color="gray"&gt;), &lt;/font&gt;&lt;font color="black"&gt;s.&lt;/font&gt;&lt;font color="blue"&gt;text&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;ctext&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;convert&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;smallint&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;2 &lt;/font&gt;&lt;font color="gray"&gt;+ &lt;/font&gt;&lt;font color="black"&gt;4 &lt;/font&gt;&lt;font color="gray"&gt;* (&lt;/font&gt;&lt;font color="black"&gt;s.&lt;/font&gt;&lt;font color="blue"&gt;status&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="gray"&gt;&amp;amp;&lt;/font&gt;&lt;font color="gray"&gt; &lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;)) &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;texttype&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;convert&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;smallint&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;0&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="blue"&gt;language&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;sysconv&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;bit&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;s.&lt;/font&gt;&lt;font color="blue"&gt;status&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="gray"&gt;&amp;amp;&lt;/font&gt;&lt;font color="gray"&gt; &lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;encrypted&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;sysconv&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;bit&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;0&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;compressed&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;s.&lt;/font&gt;&lt;font color="blue"&gt;text&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FROM &lt;/font&gt;&lt;font color="green"&gt;sys.sysschobjs&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="gray"&gt;CROSS APPLY&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="blue"&gt;OpenRowset&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;TABLE &lt;/font&gt;&lt;font color="black"&gt;SQLSRC&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;o.id&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;0&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="black"&gt;s&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;UNION &lt;/font&gt;&lt;font color="gray"&gt;ALL&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;...&lt;/font&gt;
&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

While sys.sysschobjs is generally off-limits...

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT&lt;/font&gt; * &lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="green"&gt;sys.sysschobjs&lt;/font&gt;;
&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

Results:

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;color:red;"&gt;Msg 208, Level 16, State 1, Line 1&lt;br&gt;Invalid object name 'sys.sysschobjs'.
&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

...if you really want to look at what's in there, you can do so using a DAC connection - and no, this has nothing to do with DACPACs, I am talking about the &lt;a href="http://msdn.microsoft.com/en-us/library/ms189595.aspx" title="http://msdn.microsoft.com/en-us/library/ms189595.aspx" target="_blank"&gt;Dedicated Administrator Connection&lt;/a&gt;. Once connected via the DAC, you can take a peek inside of many of these system tables that are usually hidden:

&lt;blockquote&gt;&lt;a href="http://bertrandaaron.files.wordpress.com/2011/11/tsql-24-0a.png" title="http://bertrandaaron.files.wordpress.com/2011/11/tsql-24-0a.png" target="_blank"&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/11/tsql-24-0a.png" border="0" height="136" width="750"&gt;&lt;/a&gt;&lt;br&gt;&lt;font color="#999999"&gt;&lt;i&gt;&lt;font size="2"&gt;&amp;nbsp;(click to embiggen)&lt;/font&gt;&lt;/i&gt;&lt;/font&gt;&lt;/blockquote&gt;

&lt;p&gt;But even under DAC, you can't call the other functions - you could easily change sysconv() to CONVERT(), but outside of system scope, you'll still get a syntax error on the OPENROWSET() call. So without knowing some serious SQL Server internals, you can't really determine why or how the definition is internally stored in chunks, or dig any deeper into the source...&lt;br&gt;&amp;nbsp;&lt;br&gt;&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;&lt;b&gt;sp_helptext&lt;/b&gt; is another peculiar one. It breaks up your modules by carriage return / line feed pairs, and returns each "line" as a separate row. If you have continuous strings that are longer than 255 characters, it breaks them into 255-character chunks. We can see why by looking at the definition:

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;EXEC &lt;/font&gt;&lt;font color="darkred"&gt;sp_helptext &lt;/font&gt;&lt;font color="red"&gt;'sys.sp_helptext'&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

I'm not going to reproduce the body here, but you will clearly see that there are a lot of loops, cursors and messy string manipulation routines going on in there (the procedure is 208 lines in SQL Server 2012!), making sure that no output line exceeds 255 characters. Why do they do this? Who knows - very skinny CRT screens back when the procedure was first written? The main point is that, even if you dump the results of this procedure into a #temp table, you have even more of a chance to see your search criteria straddle two rows, leading again to missing results.&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;br&gt;&lt;font size="4"&gt;&lt;font size="5"&gt;More Details&lt;/font&gt;&lt;/font&gt;&lt;b&gt;&lt;font size="4"&gt; &lt;br&gt;&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Let's demonstrate these issues with a quick example. Here is a stored procedure that is &amp;gt; 4,000 characters, and happens to have the string 'supercalifragilisticexpialidocious' straddle the 4,000-character mark. I'm using dynamic SQL here so I don't have to actually publish huge long strings on this blog (or expect you to copy them):
&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;DECLARE &lt;/font&gt;&lt;font color="#434343"&gt;@sql &lt;/font&gt;&lt;font color="blue"&gt;NVARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="magenta"&gt;MAX&lt;/font&gt;&lt;font color="gray"&gt;);&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;SET &lt;/font&gt;&lt;font color="#434343"&gt;@sql =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="red"&gt;N'CREATE PROCEDURE dbo.fooblat&lt;br&gt;AS&lt;br&gt;BEGIN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SET NOCOUNT ON;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SELECT ''' &lt;/font&gt;&lt;font color="gray"&gt;+ &lt;/font&gt;&lt;font color="magenta"&gt;REPLICATE&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="red"&gt;'x'&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;3900&lt;/font&gt;&lt;font color="gray"&gt;) + &lt;/font&gt;&lt;font color="red"&gt;''''&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;SET &lt;/font&gt;&lt;font color="#434343"&gt;@sql &lt;/font&gt;&lt;font color="gray"&gt;+=&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="red"&gt;'&amp;nbsp;&amp;nbsp;SELECT ''-supercalifragilisticexpialidocious-xxxxxxxx'';&lt;br&gt;END'&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

Now, let's see how this procedure looks using the various methods described above.

&lt;p&gt;&lt;br&gt;&lt;font size="4"&gt;INFORMATION_SCHEMA.ROUTINES&lt;/font&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Here is how the procedure is stored in the INFORMATION_SCHEMA view. I'm going to take the right-most 10 characters to show where the definition of the body gets cut off:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;ROUTINE_DEFINITION&lt;/font&gt;&lt;font color="gray"&gt;, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[end] =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="magenta"&gt;RIGHT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;ROUTINE_DEFINITION&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;10&lt;/font&gt;&lt;font color="gray"&gt;), &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;l     =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="magenta"&gt;LEN&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;ROUTINE_DEFINITION&lt;/font&gt;&lt;font color="gray"&gt;),&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dl    =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="magenta"&gt;DATALENGTH&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;ROUTINE_DEFINITION&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="green"&gt;INFORMATION_SCHEMA.ROUTINES &lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;WHERE &lt;/font&gt;&lt;font color="black"&gt;ROUTINE_NAME =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="red"&gt;'fooblat'&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

Results:&amp;nbsp;

&lt;blockquote&gt;
&lt;p&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/11/tsql-24-1.png" height="251" width="580"&gt;&lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, seeing as the whole word isn't even there, and that the metadata has only revealed the first 4,000 characters of our procedure, it should come as no surprise that the following search will yield 0 results:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;ROUTINE_NAME&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="green"&gt;INFORMATION_SCHEMA.ROUTINES&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;WHERE &lt;/font&gt;&lt;font color="black"&gt;ROUTINE_DEFINITION &lt;/font&gt;&lt;font color="gray"&gt;LIKE &lt;/font&gt;&lt;font color="red"&gt;'%supercalifragilistic%'&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

Results: 

&lt;blockquote&gt;
&lt;p&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/11/tsql-24-correction.png" border="0" height="163" width="445"&gt; &lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So it looks like I've spoiled the party for the INFORMATION_SCHEMA views once again. Sorry about that.&lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;br&gt;&lt;font size="4"&gt;sys.syscomments&lt;/font&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;As described above, we can see with the following query that sys.syscomments returns our procedure split up into multiple rows, and our search term once again straddles rows:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;colid&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;[text]&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;l =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="magenta"&gt;LEN&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;[text]&lt;/font&gt;&lt;font color="gray"&gt;), &lt;/font&gt;&lt;font color="black"&gt;dl =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="magenta"&gt;DATALENGTH&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;[text]&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="green"&gt;sys.syscomments &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;WHERE &lt;/font&gt;&lt;font color="black"&gt;id =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="magenta"&gt;OBJECT_ID&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="red"&gt;'dbo.fooblat'&lt;/font&gt;&lt;font color="gray"&gt;);&lt;/font&gt;
&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

Results: 

&lt;blockquote&gt;
&lt;p&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/11/tsql-24-3.png" height="191" width="523"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Which in turn makes a search for this term useless:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="magenta"&gt;OBJECT_NAME&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;[id]&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="green"&gt;sys.syscomments&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;WHERE &lt;/font&gt;&lt;font color="black"&gt;[text] &lt;/font&gt;&lt;font color="gray"&gt;LIKE &lt;/font&gt;&lt;font color="red"&gt;'%supercalifragilistic%'&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

Results:&amp;nbsp;

&lt;blockquote&gt;
&lt;p&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/11/tsql-24-4.png" height="157" width="410"&gt;&lt;/p&gt;
&lt;/blockquote&gt;
So, it doesn't seem like sys.syscomments is going to be a useful way to find and retrieve procedure definitions, either.&lt;br&gt;&amp;nbsp;&amp;nbsp;

&lt;/blockquote&gt;&lt;p&gt;&lt;font size="4"&gt;sp_helptext&lt;/font&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I won't get into the whole rigamarole of dumping the output of sp_helptext for all stored procedures into a #temp table and searching there, since I think you are all smarter than to try this in the first place. But I will show the output of sp_helptext against our procedure, so you can once again see how the body is chunked out into multiple rows:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;EXEC &lt;/font&gt;&lt;font color="darkred"&gt;sp_helptext &lt;/font&gt;&lt;font color="red"&gt;'dbo.fooblat'&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

Results: 

&lt;blockquote&gt;
&lt;p&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/11/tsql-24-5.png" height="577" width="602"&gt;&amp;nbsp;&lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now it turns out that, in this case, the magic word didn't straddle rows (so a convoluted search process might have still yielded this procedure), but that is just dumb luck. With a forced CR/LF pair every 255 characters, and depending on your coding style, you are certainly bound to see some straddling here that will make searches very unreliable. Again, I don't expect any of you are doing anything like this, but wanted to mention it for completeness.&lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;br&gt;&lt;font size="5"&gt;Alternatives&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;I wouldn't be writing this post if the intention was just to crap on old-school methods for finding and retrieving procedures and functions. I see lots of folks on StackOverflow and dba.StackExchange.com still responding to queries with suggestions to use syscomments or INFORMATION_SCHEMA, even though they may not realize that better alternatives exist. I hope I've convinced you above that these old approaches aren't the way to go. So what should you use instead?&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;br&gt;&lt;font size="4"&gt;OBJECT_DEFINITION() &lt;/font&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Since SQL Server 2005, this has been my go-to place for retrieving or searching the definition of procedures and functions. Now, keep in mind this is much easier to demonstrate when we switch to Results to Text mode (Ctrl+T):&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="magenta"&gt;OBJECT_DEFINITION&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="magenta"&gt;OBJECT_ID&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="red"&gt;'dbo.fooblat'&lt;/font&gt;&lt;font color="gray"&gt;));&lt;/font&gt;
&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

Results:

&lt;blockquote&gt;
  
&lt;p&gt;&amp;nbsp;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/11/tsql-24-6.png" height="266" width="507"&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So you can see that our big long line actually gets returned the way it was intended. This gives me much more confidence about a
 search, since there are no forced formatting changes or truncation that
 can screw things up. &lt;/p&gt;

&lt;p&gt;Now, if we want to find all stored procedures that contain the text 'supercalifragilistic'? Let's switch back to Results to Grid mode first (Ctrl + D) and then run this query. Using a dedicated view for only procedures prevents us from needlessly looking at all of the other object types:&lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;[schema] =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="magenta"&gt;OBJECT_SCHEMA_NAME&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;[object_id]&lt;/font&gt;&lt;font color="gray"&gt;), &lt;/font&gt;&lt;font color="black"&gt;name&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="green"&gt;sys.procedures&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;WHERE &lt;/font&gt;&lt;font color="magenta"&gt;OBJECT_DEFINITION&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;[object_id]&lt;/font&gt;&lt;font color="gray"&gt;) LIKE &lt;/font&gt;&lt;font color="red"&gt;'%supercalifragilistic%'&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

Results:&amp;nbsp;

&lt;blockquote&gt;
&lt;p&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/11/tsql-24-7.png" height="174" width="566"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/blockquote&gt;
Unlike the three methods above, we finally have success! If we want to expand our search to procedures and functions, we can use sys.objects and a filter on [type]:

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;[schema] =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="magenta"&gt;OBJECT_SCHEMA_NAME&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;[object_id]&lt;/font&gt;&lt;font color="gray"&gt;), &lt;/font&gt;&lt;font color="black"&gt;name&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="green"&gt;sys.objects&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;WHERE &lt;/font&gt;&lt;font color="magenta"&gt;OBJECT_DEFINITION&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;[object_id]&lt;/font&gt;&lt;font color="gray"&gt;) LIKE &lt;/font&gt;&lt;font color="red"&gt;'%supercalifragilistic%'&lt;/font&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="gray"&gt;AND &lt;/font&gt;&lt;font color="black"&gt;[type] &lt;/font&gt;&lt;font color="gray"&gt;IN&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="red"&gt;'P'&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="red"&gt;'IF'&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="red"&gt;'FN'&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="red"&gt;'TF'&lt;/font&gt;&lt;font color="gray"&gt;);&lt;/font&gt;
&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

This yields the same results as above. &lt;br&gt;&lt;/blockquote&gt;

&lt;p&gt;&lt;br&gt;&lt;font size="4"&gt;sys.sql_modules&lt;/font&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is a view that contains the definition and other properties for many types of objects - views, procedures, functions, triggers, etc. Under the covers it uses OBJECT_DEFINITION() to expose the body through the column [definition]. So borrowing from the query above, we could use sys.sql_modules instead of referencing the function directly, in case we want to use more convoluted joins or filters, or wanted other properties that come directly from sys.sql_modules:&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;[schema] =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="magenta"&gt;OBJECT_SCHEMA_NAME&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;o.[object_id]&lt;/font&gt;&lt;font color="gray"&gt;), &lt;/font&gt;&lt;font color="black"&gt;o.name&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="green"&gt;sys.objects &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;o&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INNER JOIN &lt;/font&gt;&lt;font color="green"&gt;sys.sql_modules &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;m&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;ON &lt;/font&gt;&lt;font color="black"&gt;o.[object_id] =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="black"&gt;m.[object_id]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;WHERE &lt;/font&gt;&lt;font color="black"&gt;m.[definition] &lt;/font&gt;&lt;font color="gray"&gt;LIKE &lt;/font&gt;&lt;font color="red"&gt;'%supercalifragilistic%'&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;AND &lt;/font&gt;&lt;font color="black"&gt;o.[type] &lt;/font&gt;&lt;font color="gray"&gt;IN&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="red"&gt;'P'&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="red"&gt;'IF'&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="red"&gt;'FN'&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="red"&gt;'TF'&lt;/font&gt;&lt;font color="gray"&gt;);&lt;/font&gt;
&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

Again, this will yield the same results as above.&lt;br&gt;&amp;nbsp;&lt;br&gt;&lt;/blockquote&gt;


&lt;p&gt;&lt;font size="5"&gt;Conclusion&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;Yes, sp_helptext is easy to type, and it can be tough to shake old habits of using INFORMATION_SCHEMA or syscomments. But I think you will be better off overall if you use sys.sql_modules and OBJECT_DEFINITION() for all of your metadata access to procedures and functions. They will always return the body of the module as intended, without chunking or unnecessary carriage returns and line feeds.&lt;br&gt;&amp;nbsp;&lt;br&gt;&lt;/p&gt;</description></item></channel></rss>