<?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>Thu, 09 Feb 2012 19:36:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<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>

