<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; 2008 &#8211; Enhenced TRIM() Function &#8211; Remove Trailing Spaces, Leading Spaces, White Space, Tabs, Carriage Returns, Line Feeds</title>
	<atom:link href="http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Sat, 25 May 2013 15:33:52 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Prad</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-418179</link>
		<dc:creator><![CDATA[Prad]]></dc:creator>
		<pubDate>Tue, 05 Feb 2013 15:57:52 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-418179</guid>
		<description><![CDATA[Pinal&#039;s script works perfect for the line feeds and tabs at the end which doesnt work out by just using Trim or Ltrim or Rtrim.]]></description>
		<content:encoded><![CDATA[<p>Pinal&#8217;s script works perfect for the line feeds and tabs at the end which doesnt work out by just using Trim or Ltrim or Rtrim.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER &#8211; TRIM Function to Remove Leading and Trailing Spaces of String &#8211; SQL in Sixty Seconds #040 &#8211; Video &#171; SQL Server Journey with SQL Authority</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-411522</link>
		<dc:creator><![CDATA[SQL SERVER &#8211; TRIM Function to Remove Leading and Trailing Spaces of String &#8211; SQL in Sixty Seconds #040 &#8211; Video &#171; SQL Server Journey with SQL Authority]]></dc:creator>
		<pubDate>Wed, 23 Jan 2013 01:30:42 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-411522</guid>
		<description><![CDATA[[...] Enhenced TRIM() Function – Remove Trailing Spaces, Leading Spaces, White Space, Tabs, Carriage Ret... [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Enhenced TRIM() Function – Remove Trailing Spaces, Leading Spaces, White Space, Tabs, Carriage Ret&#8230; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SP</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-406097</link>
		<dc:creator><![CDATA[SP]]></dc:creator>
		<pubDate>Thu, 10 Jan 2013 15:46:52 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-406097</guid>
		<description><![CDATA[Hi Madhivanan, 
For eg: i have a column amount numeric(23,8).
If i save 4.5, it is stored as 4.50000000.
I want it to be stored as 4.5
All the blogs on the internet have mentioned about handling such situations by trimming the trailing zeros in the application.
I was just wondering if sqlserver has any setting to be done at the database level to handle this.

Thanks,
SP]]></description>
		<content:encoded><![CDATA[<p>Hi Madhivanan,<br />
For eg: i have a column amount numeric(23,8).<br />
If i save 4.5, it is stored as 4.50000000.<br />
I want it to be stored as 4.5<br />
All the blogs on the internet have mentioned about handling such situations by trimming the trailing zeros in the application.<br />
I was just wondering if sqlserver has any setting to be done at the database level to handle this.</p>
<p>Thanks,<br />
SP</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-405242</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Tue, 08 Jan 2013 13:26:10 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-405242</guid>
		<description><![CDATA[What do you meant by &quot;addition of trailing 0&#039;s? Can you give examples?]]></description>
		<content:encoded><![CDATA[<p>What do you meant by &#8220;addition of trailing 0&#8242;s? Can you give examples?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SP</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-404926</link>
		<dc:creator><![CDATA[SP]]></dc:creator>
		<pubDate>Mon, 07 Jan 2013 17:58:26 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-404926</guid>
		<description><![CDATA[is there anyway we can avoid the addition of these trailing 0&#039;s after the decimal value for  numeric field at the database level?]]></description>
		<content:encoded><![CDATA[<p>is there anyway we can avoid the addition of these trailing 0&#8242;s after the decimal value for  numeric field at the database level?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Luke Merrett</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-378114</link>
		<dc:creator><![CDATA[Luke Merrett]]></dc:creator>
		<pubDate>Wed, 21 Nov 2012 14:50:42 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-378114</guid>
		<description><![CDATA[Once issue I encountered using these functions was that it doesn’t remove char(160) (Otherwise known as non-breaking space). Spent a long time trying to ascertain why a row in our database still had a whitespace even after trimming.

Only figured it out by using SELECT ASCII() and realising it wasn’t a normal space.

If anyone has this issue add CHAR(160) to the trimchars parameter.]]></description>
		<content:encoded><![CDATA[<p>Once issue I encountered using these functions was that it doesn’t remove char(160) (Otherwise known as non-breaking space). Spent a long time trying to ascertain why a row in our database still had a whitespace even after trimming.</p>
<p>Only figured it out by using SELECT ASCII() and realising it wasn’t a normal space.</p>
<p>If anyone has this issue add CHAR(160) to the trimchars parameter.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Luke Merrett</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-378112</link>
		<dc:creator><![CDATA[Luke Merrett]]></dc:creator>
		<pubDate>Wed, 21 Nov 2012 14:48:59 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-378112</guid>
		<description><![CDATA[Once issue I encountered using these functions was that it doesn&#039;t remove char(160) (Otherwise known as whitespace).  Spent a long time trying to ascertain why a row in our database still had a whitespace even after trimming.

Only figured it out by using SELECT ASCII() and realising it wasn&#039;t a space.

If anyone has this issue add CHAR(160) to the trimchars parameter.]]></description>
		<content:encoded><![CDATA[<p>Once issue I encountered using these functions was that it doesn&#8217;t remove char(160) (Otherwise known as whitespace).  Spent a long time trying to ascertain why a row in our database still had a whitespace even after trimming.</p>
<p>Only figured it out by using SELECT ASCII() and realising it wasn&#8217;t a space.</p>
<p>If anyone has this issue add CHAR(160) to the trimchars parameter.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jitendra</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-316407</link>
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Fri, 20 Jul 2012 13:18:27 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-316407</guid>
		<description><![CDATA[Really Thanks a lot..]]></description>
		<content:encoded><![CDATA[<p>Really Thanks a lot..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Igor Bekker</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-306287</link>
		<dc:creator><![CDATA[Igor Bekker]]></dc:creator>
		<pubDate>Wed, 27 Jun 2012 03:54:05 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-306287</guid>
		<description><![CDATA[Hi,

I am using this awesome script, but I ran into a problem
It trims letter N at the end of the field

So if have have LTrim(RTrim(&#039;Ray Ban&#039;) =&gt; the result will show Ray Ba

any suggestions on how to fix this?

thanks
Igor]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I am using this awesome script, but I ran into a problem<br />
It trims letter N at the end of the field</p>
<p>So if have have LTrim(RTrim(&#8216;Ray Ban&#8217;) =&gt; the result will show Ray Ba</p>
<p>any suggestions on how to fix this?</p>
<p>thanks<br />
Igor</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-287933</link>
		<dc:creator><![CDATA[Peter]]></dc:creator>
		<pubDate>Thu, 24 May 2012 10:09:07 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-287933</guid>
		<description><![CDATA[WHILE RTRIM(@Risk) LIKE &#039;%[&#039;+CHAR(10) + CHAR(13)+&#039;]&#039;
    SELECT @Risk = RTRIM(LEFT(@Risk, LEN(@Risk)-1))]]></description>
		<content:encoded><![CDATA[<p>WHILE RTRIM(@Risk) LIKE &#8216;%['+CHAR(10) + CHAR(13)+']&#8216;<br />
    SELECT @Risk = RTRIM(LEFT(@Risk, LEN(@Risk)-1))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-182947</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Mon, 24 Oct 2011 15:58:26 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-182947</guid>
		<description><![CDATA[This will give you what you want

select right(col,3) from table]]></description>
		<content:encoded><![CDATA[<p>This will give you what you want</p>
<p>select right(col,3) from table</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ernie</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-181474</link>
		<dc:creator><![CDATA[ernie]]></dc:creator>
		<pubDate>Fri, 21 Oct 2011 07:19:23 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-181474</guid>
		<description><![CDATA[is it possible to trim data based on the number of characters and not just the spaces in an sql query. example: i just wanna get the last 3 digits of an int column which already has 50000 rows.]]></description>
		<content:encoded><![CDATA[<p>is it possible to trim data based on the number of characters and not just the spaces in an sql query. example: i just wanna get the last 3 digits of an int column which already has 50000 rows.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Madhivanan</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-62377</link>
		<dc:creator><![CDATA[Madhivanan]]></dc:creator>
		<pubDate>Mon, 08 Mar 2010 09:55:11 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-62377</guid>
		<description><![CDATA[There is no built-in function in SQL Server 2008 for trim
If you get input values from front end application, remove the spaces there]]></description>
		<content:encoded><![CDATA[<p>There is no built-in function in SQL Server 2008 for trim<br />
If you get input values from front end application, remove the spaces there</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Padma</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-54834</link>
		<dc:creator><![CDATA[Padma]]></dc:creator>
		<pubDate>Thu, 13 Aug 2009 22:25:29 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-54834</guid>
		<description><![CDATA[Pinal,

In my working environment we are accepting multiple inputs (parameters) and we have to trim the white spaces before and after the input value.

I have the function which performs very badly, takes lots of time. Now we are in plan of moving to SQL server 2008.  I have heard that there is a function trim() available in SQL 2008. Can you please help me with the code which trims spaces for multiple comma separated input values.]]></description>
		<content:encoded><![CDATA[<p>Pinal,</p>
<p>In my working environment we are accepting multiple inputs (parameters) and we have to trim the white spaces before and after the input value.</p>
<p>I have the function which performs very badly, takes lots of time. Now we are in plan of moving to SQL server 2008.  I have heard that there is a function trim() available in SQL 2008. Can you please help me with the code which trims spaces for multiple comma separated input values.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER – Connect Item – Vote for Feature Request Function TRIM Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-52669</link>
		<dc:creator><![CDATA[SQL SERVER – Connect Item – Vote for Feature Request Function TRIM Journey to SQL Authority with Pinal Dave]]></dc:creator>
		<pubDate>Wed, 03 Jun 2009 01:31:57 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-52669</guid>
		<description><![CDATA[[...] SQL SERVER – 2008 – Enhenced TRIM() Function – Remove Trailing Spaces, Leading Spaces, White S... [...]]]></description>
		<content:encoded><![CDATA[<p>[...] SQL SERVER – 2008 – Enhenced TRIM() Function – Remove Trailing Spaces, Leading Spaces, White S&#8230; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LOL@Enhenced</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-45018</link>
		<dc:creator><![CDATA[LOL@Enhenced]]></dc:creator>
		<pubDate>Mon, 22 Dec 2008 22:36:13 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-45018</guid>
		<description><![CDATA[I&#039;m going with phil&#039;s function. It doesn&#039;t do any more or less than what I want.]]></description>
		<content:encoded><![CDATA[<p>I&#8217;m going with phil&#8217;s function. It doesn&#8217;t do any more or less than what I want.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Speednet</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-43792</link>
		<dc:creator><![CDATA[Speednet]]></dc:creator>
		<pubDate>Sat, 18 Oct 2008 15:09:05 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-43792</guid>
		<description><![CDATA[@phil Factor: If you try my version of SuperTrim, you will see that it does NOT trim to 8000 characters.]]></description>
		<content:encoded><![CDATA[<p>@phil Factor: If you try my version of SuperTrim, you will see that it does NOT trim to 8000 characters.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nathan</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-43778</link>
		<dc:creator><![CDATA[Nathan]]></dc:creator>
		<pubDate>Fri, 17 Oct 2008 16:19:59 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-43778</guid>
		<description><![CDATA[Pinal, thanks for all your posts.  May I suggest using the spelling &quot;Enhanced&quot; instead of &quot;Enhenced&quot; in your post?

Thanks again!]]></description>
		<content:encoded><![CDATA[<p>Pinal, thanks for all your posts.  May I suggest using the spelling &#8220;Enhanced&#8221; instead of &#8220;Enhenced&#8221; in your post?</p>
<p>Thanks again!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: phil Factor</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-43661</link>
		<dc:creator><![CDATA[phil Factor]]></dc:creator>
		<pubDate>Sun, 12 Oct 2008 10:41:41 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-43661</guid>
		<description><![CDATA[The function definitely just returns the first 8000 characters. This version definitely works a lot better

alter FUNCTION dbo.LTrimX(@str VARCHAR(MAX)) RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @trimchars VARCHAR(10)
SET @trimchars = CHAR(9)+CHAR(10)+CHAR(13)+CHAR(32)
IF @str LIKE &#039;[&#039; + @trimchars + &#039;]%&#039; 
	SET @str =STUFF ( @str , 1 , PATINDEX(&#039;%[^&#039; + @trimchars + &#039;]%&#039;, @str)-1 ,&#039;&#039; )
RETURN @str
END
GO]]></description>
		<content:encoded><![CDATA[<p>The function definitely just returns the first 8000 characters. This version definitely works a lot better</p>
<p>alter FUNCTION dbo.LTrimX(@str VARCHAR(MAX)) RETURNS VARCHAR(MAX)<br />
AS<br />
BEGIN<br />
DECLARE @trimchars VARCHAR(10)<br />
SET @trimchars = CHAR(9)+CHAR(10)+CHAR(13)+CHAR(32)<br />
IF @str LIKE &#8216;[' + @trimchars + ']%&#8217;<br />
	SET @str =STUFF ( @str , 1 , PATINDEX(&#8216;%[^' + @trimchars + ']%&#8217;, @str)-1 ,&#8221; )<br />
RETURN @str<br />
END<br />
GO</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phil Factor</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-43660</link>
		<dc:creator><![CDATA[Phil Factor]]></dc:creator>
		<pubDate>Sun, 12 Oct 2008 10:14:04 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-43660</guid>
		<description><![CDATA[Oh dear, surely, unless I&#039;m missing something  these functions will just return the first 8000 characters if they do a Trim, and so could cause havoc if someone uses it in SQL Server 2005/8 without realising its limitations, or you have it in place in a production system and the data changes. You&#039;d do better if it took and returned Varchar(8000). Then it might flag up the weakness in the algorithm.]]></description>
		<content:encoded><![CDATA[<p>Oh dear, surely, unless I&#8217;m missing something  these functions will just return the first 8000 characters if they do a Trim, and so could cause havoc if someone uses it in SQL Server 2005/8 without realising its limitations, or you have it in place in a production system and the data changes. You&#8217;d do better if it took and returned Varchar(8000). Then it might flag up the weakness in the algorithm.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Speednet</title>
		<link>http://blog.sqlauthority.com/2008/10/10/sql-server-2008-enhenced-trim-function-remove-trailing-spaces-leading-spaces-white-space-tabs-carriage-returns-line-feeds/#comment-43652</link>
		<dc:creator><![CDATA[Speednet]]></dc:creator>
		<pubDate>Sat, 11 Oct 2008 04:43:24 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346#comment-43652</guid>
		<description><![CDATA[Hi Pinal,

May I suggest some improvements?

I tend to call my whitespace trimmers &quot;SuperTrim&quot; functions, so please excuse the difference in naming.

(This will probably lose its indenting when I paste it.)

---------
CREATE FUNCTION dbo.SuperTrimLeft(@str varchar(MAX)) RETURNS varchar(MAX)
AS
BEGIN
	IF (ASCII(LEFT(@str, 1)) &lt; 33) BEGIN
		SET @str = STUFF(@str, 1, PATINDEX(&#039;%[^&#039;+CHAR(0)+&#039;-&#039;+CHAR(32)+&#039;]%&#039;, @str) - 1, &#039;&#039;);
	END;

	RETURN @str;
END;
---------

I think it&#039;s a big performance increase, because it does a numeric test of the first character, rather than a relatively expensive pattern test.  If the first character is not a space or some other control character, no pattern is tested at all.

Then, instead of testing for specific control characters, why not test for the whole range of zero (0) through 32 (space)?

The function above does the test for first non-whitespace char and the trimming all in one statement.

I couldn&#039;t think of a faster or more efficient way to do it.  I did some testing, and it seemed to work well.

I haven&#039;t looked at different ways to do SuperTrimRight yet, but the ways you outlined should work with this function OK.

Thanks for the great SQL blog!

-Todd (&quot;Speednet&quot;)]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>May I suggest some improvements?</p>
<p>I tend to call my whitespace trimmers &#8220;SuperTrim&#8221; functions, so please excuse the difference in naming.</p>
<p>(This will probably lose its indenting when I paste it.)</p>
<p>&#8212;&#8212;&#8212;<br />
CREATE FUNCTION dbo.SuperTrimLeft(@str varchar(MAX)) RETURNS varchar(MAX)<br />
AS<br />
BEGIN<br />
	IF (ASCII(LEFT(@str, 1)) &lt; 33) BEGIN<br />
		SET @str = STUFF(@str, 1, PATINDEX(&#8216;%[^'+CHAR(0)+'-'+CHAR(32)+']%&#8217;, @str) &#8211; 1, &#8221;);<br />
	END;</p>
<p>	RETURN @str;<br />
END;<br />
&#8212;&#8212;&#8212;</p>
<p>I think it&#8217;s a big performance increase, because it does a numeric test of the first character, rather than a relatively expensive pattern test.  If the first character is not a space or some other control character, no pattern is tested at all.</p>
<p>Then, instead of testing for specific control characters, why not test for the whole range of zero (0) through 32 (space)?</p>
<p>The function above does the test for first non-whitespace char and the trimming all in one statement.</p>
<p>I couldn&#8217;t think of a faster or more efficient way to do it.  I did some testing, and it seemed to work well.</p>
<p>I haven&#8217;t looked at different ways to do SuperTrimRight yet, but the ways you outlined should work with this function OK.</p>
<p>Thanks for the great SQL blog!</p>
<p>-Todd (&#8220;Speednet&#8221;)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
