<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	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>SQL Server Journey with SQL Authority &#187; SQL String</title>
	<atom:link href="http://blog.sqlauthority.com/category/sql-string/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Sun, 12 Feb 2012 09:51:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.sqlauthority.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/08e35387c05b61340e885b1763a69d9f?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>SQL Server Journey with SQL Authority &#187; SQL String</title>
		<link>http://blog.sqlauthority.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.sqlauthority.com/osd.xml" title="SQL Server Journey with SQL Authority" />
	<atom:link rel='hub' href='http://blog.sqlauthority.com/?pushpress=hub'/>
		<item>
		<title>SQL SERVER &#8211; Concat Function in SQL Server &#8211; SQL Concatenation</title>
		<link>http://blog.sqlauthority.com/2010/11/25/sql-server-concat-function-in-sql-server-sql-concatenation/</link>
		<comments>http://blog.sqlauthority.com/2010/11/25/sql-server-concat-function-in-sql-server-sql-concatenation/#comments</comments>
		<pubDate>Thu, 25 Nov 2010 01:30:44 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=10977</guid>
		<description><![CDATA[Earlier this week, I was delivering Advanced BI training on the subject of &#8220;SQL Server 2008 R2&#8243;. I had great time delivering the session. During the session, we talked about SQL Server 2010 Denali. Suddenly one of the attendees suggested his displeasure for the product. He said, even though, SQL Server is now in moving [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=10977&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Earlier this week, I was delivering Advanced BI training on the subject of &#8220;SQL Server 2008 R2&#8243;. I had great time delivering the session. During the session, we talked about<a title="SQLAuthority News - What's New in SQL Server &quot;Denali&quot;" href="http://blog.sqlauthority.com/2010/11/24/sqlauthority-news-whats-new-in-sql-server-denali/" target="_blank"> SQL Server 2010 Denali</a>. Suddenly one of the attendees suggested his displeasure for the product. He said, even though, SQL Server is now in moving very fast and have proved many times a good enterprise solution, it does not have some basic functions. I naturally asked him for example and he suggested CONCAT() which exists in MySQL and Oracle.</p>
<p style="text-align:justify;">The answer is very simple &#8211; the equalent function in SQL Server to CONCAT() is &#8216;+&#8217; (plus operator without quotes).</p>
<p style="text-align:justify;"><strong>Method 1: Concatenating two strings</strong></p>
<p><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:red;">'FirstName' </span><span style="color:gray;">+ </span><span style="color:red;">' ' </span><span style="color:gray;">+ </span><span style="color:red;">'LastName' </span><span style="color:blue;">AS </span><span style="color:black;">FullName<br />
</span></code></p>
<p style="text-align:justify;"><strong>Method 2: Concatenating two Numbers</strong></p>
<p><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:black;">1 </span><span style="color:blue;">AS VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">)) + </span><span style="color:red;">'R' </span><span style="color:gray;">+ </span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:black;">2 </span><span style="color:blue;">AS VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">))</span></code></p>
<p style="text-align:justify;"><strong>Method 3: Concatenating values from table columns</strong></p>
<p><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">FirstName </span><span style="color:gray;">+ </span><span style="color:red;">' ' </span><span style="color:gray;">+ </span><span style="color:black;">LastName<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">AdventureWorks.Person.Contact</span></code></p>
<p style="text-align:justify;">Well, this may look very simple but sometime it is very difficult to find the information for simple things only.</p>
<p style="text-align:justify;">Do you have any such example which you would like to share with community?</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
<br />Filed under: <a href='http://blog.sqlauthority.com/category/tech/pinal-dave/'>Pinal Dave</a>, <a href='http://blog.sqlauthority.com/category/technology/sql/'>SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-authority/'>SQL Authority</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-query/'>SQL Query</a>, <a href='http://blog.sqlauthority.com/category/tech/sql-scripts/'>SQL Scripts</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-server/'>SQL Server</a>, <a href='http://blog.sqlauthority.com/category/sql-string/'>SQL String</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-tips-and-tricks/'>SQL Tips and Tricks</a>, <a href='http://blog.sqlauthority.com/category/technology/t-sql/'>T SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/'>Technology</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/10977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/10977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/10977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/10977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/10977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/10977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/10977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/10977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/10977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/10977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/10977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/10977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/10977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/10977/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=10977&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2010/11/25/sql-server-concat-function-in-sql-server-sql-concatenation/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER – Get Numeric Value From Alpha Numeric String – Get Numbers Only</title>
		<link>http://blog.sqlauthority.com/2010/09/25/sql-server-get-numeric-value-from-alpha-numeric-string-get-numbers-only/</link>
		<comments>http://blog.sqlauthority.com/2010/09/25/sql-server-get-numeric-value-from-alpha-numeric-string-get-numbers-only/#comments</comments>
		<pubDate>Sat, 25 Sep 2010 01:30:08 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=10366</guid>
		<description><![CDATA[I have earlier wrote article about SQL SERVER – Get Numeric Value From Alpha Numeric String – UDF for Get Numeric Numbers Only and it was very handy tool for me. Recently blog reader and SQL Expert Christofer has left excellent improvement to this logic. Here is his contribution. He has provided Stored Procedure and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=10366&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">I have earlier wrote article about <strong><a href="http://blog.sqlauthority.com/2008/10/14/sql-server-get-numeric-value-from-alpha-numeric-string-udf-for-get-numeric-numbers-only/" target="_blank">SQL SERVER – Get Numeric Value From Alpha Numeric String – UDF for Get Numeric Numbers Only</a></strong> and it was very handy tool for me. Recently blog reader and SQL Expert <strong><a href="http://blog.sqlauthority.com/2008/10/14/sql-server-get-numeric-value-from-alpha-numeric-string-udf-for-get-numeric-numbers-only/#comment-89217">Christofer</a></strong> has left excellent improvement to this logic. Here is his contribution. He has provided Stored Procedure and the same can be easily converted to Function.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE PROCEDURE </span><span style="color:black;">[dbo].[CleanDataFromAlpha]<br />
</span><span style="color:#434343;">@alpha </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">50</span><span style="color:gray;">),<br />
</span><span style="color:#434343;">@decimal </span><span style="color:blue;">DECIMAL</span><span style="color:gray;">(</span><span style="color:black;">14</span><span style="color:gray;">, </span><span style="color:black;">5</span><span style="color:gray;">) </span><span style="color:black;">OUTPUT<br />
</span><span style="color:blue;">AS BEGIN<br />
SET NOCOUNT ON</span><span style="color:gray;">;<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@ErrorMsg </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">50</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@Pos </span><span style="color:blue;">INT<br />
DECLARE </span><span style="color:#434343;">@CommaPos </span><span style="color:blue;">INT<br />
DECLARE </span><span style="color:#434343;">@ZeroExists </span><span style="color:blue;">INT<br />
DECLARE </span><span style="color:#434343;">@alphaReverse </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">50</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@NumPos </span><span style="color:blue;">INT<br />
DECLARE </span><span style="color:#434343;">@Len </span><span style="color:blue;">INT<br />
</span><span style="color:green;">-- 1 Reverse the alpha in order to get the last position of a numeric value<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@alphaReverse </span><span style="color:blue;">= </span><span style="color:magenta;">REVERSE</span><span style="color:gray;">(</span><span style="color:#434343;">@alpha</span><span style="color:gray;">)<br />
</span><span style="color:green;">-- 2 Get the last position of a numeric figure<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@NumPos </span><span style="color:blue;">= </span><span style="color:magenta;">PATINDEX</span><span style="color:gray;">(</span><span style="color:red;">'%[0-9]%'</span><span style="color:gray;">, </span><span style="color:#434343;">@alphaReverse</span><span style="color:gray;">)<br />
</span><span style="color:green;">-- 3 Get the lenght of the string<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@Len </span><span style="color:blue;">= </span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:#434343;">@alpha</span><span style="color:gray;">)<br />
</span><span style="color:green;">-- 4 Add a comma after the numeric data in case it's no decimal number<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@alpha </span><span style="color:blue;">= </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@alpha</span><span style="color:gray;">, </span><span style="color:black;">1</span><span style="color:gray;">, (</span><span style="color:#434343;">@Len </span><span style="color:gray;">- </span><span style="color:#434343;">@NumPos </span><span style="color:gray;">+ </span><span style="color:black;">1</span><span style="color:gray;">))<br />
+ </span><span style="color:red;">','<br />
</span><span style="color:gray;">+ </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@alpha</span><span style="color:gray;">, (</span><span style="color:#434343;">@Len </span><span style="color:gray;">- </span><span style="color:#434343;">@NumPos </span><span style="color:gray;">+ </span><span style="color:black;">2</span><span style="color:gray;">), </span><span style="color:black;">50</span><span style="color:gray;">)<br />
</span><span style="color:green;">-- Check if there is a zero (0) in the @alpha, then we later set the @decimal to 0<br />
-- if it's 0 after the handling, else we set @decimal to NULL<br />
-- If 0 no match, else there is a match<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@ZeroExists </span><span style="color:blue;">= CHARINDEX </span><span style="color:gray;">( </span><span style="color:red;">'0' </span><span style="color:gray;">, </span><span style="color:#434343;">@alpha </span><span style="color:gray;">,</span><span style="color:black;">1 </span><span style="color:gray;">)<br />
</span><span style="color:green;">-- Find position of , (comma)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@CommaPos </span><span style="color:blue;">= </span><span style="color:black;">1<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@CommaPos </span><span style="color:blue;">= </span><span style="color:magenta;">PATINDEX</span><span style="color:gray;">(</span><span style="color:red;">'%,%'</span><span style="color:gray;">, </span><span style="color:#434343;">@alpha</span><span style="color:gray;">)<br />
</span><span style="color:blue;">IF </span><span style="color:gray;">(</span><span style="color:#434343;">@CommaPos </span><span style="color:blue;">= </span><span style="color:red;">''</span><span style="color:gray;">) </span><span style="color:blue;">BEGIN<br />
SET </span><span style="color:#434343;">@CommaPos </span><span style="color:blue;">= </span><span style="color:black;">20<br />
</span><span style="color:blue;">END<br />
SET </span><span style="color:#434343;">@Pos </span><span style="color:blue;">= </span><span style="color:magenta;">PATINDEX</span><span style="color:gray;">(</span><span style="color:red;">'%[^0-9]%'</span><span style="color:gray;">,</span><span style="color:#434343;">@alpha</span><span style="color:gray;">)<br />
</span><span style="color:green;">-- Replaces any aplha with '0' since we otherwice can't keep track of where the decimal<br />
-- should be put in. We assume the numeric number has no aplhe inside. The regular way<br />
-- to solve this is to replace with ”, but then we miss the way to find the place to<br />
-- put in the decimal.<br />
</span><span style="color:blue;">WHILE </span><span style="color:gray;">(</span><span style="color:#434343;">@Pos </span><span style="color:gray;">&gt; </span><span style="color:black;">0</span><span style="color:gray;">) </span><span style="color:blue;">BEGIN<br />
SET </span><span style="color:#434343;">@alpha </span><span style="color:blue;">= </span><span style="color:magenta;">STUFF</span><span style="color:gray;">(</span><span style="color:#434343;">@alpha</span><span style="color:gray;">, </span><span style="color:#434343;">@pos</span><span style="color:gray;">, </span><span style="color:black;">1</span><span style="color:gray;">, </span><span style="color:red;">'0'</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@Pos </span><span style="color:blue;">= </span><span style="color:magenta;">PATINDEX</span><span style="color:gray;">(</span><span style="color:red;">'%[^0-9]%'</span><span style="color:gray;">,</span><span style="color:#434343;">@alpha</span><span style="color:gray;">)<br />
</span><span style="color:blue;">END<br />
IF </span><span style="color:gray;">(</span><span style="color:#434343;">@alpha </span><span style="color:blue;">IS </span><span style="color:gray;">NOT NULL AND </span><span style="color:#434343;">@alpha </span><span style="color:gray;">!= </span><span style="color:red;">''</span><span style="color:gray;">) </span><span style="color:blue;">BEGIN<br />
SET </span><span style="color:#434343;">@decimal </span><span style="color:blue;">= </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">DECIMAL</span><span style="color:gray;">(</span><span style="color:black;">14</span><span style="color:gray;">, </span><span style="color:black;">5</span><span style="color:gray;">), </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@alpha</span><span style="color:gray;">, </span><span style="color:black;">1</span><span style="color:gray;">, (</span><span style="color:#434343;">@CommaPos </span><span style="color:gray;">- </span><span style="color:black;">1</span><span style="color:gray;">))<br />
+ </span><span style="color:red;">'.'<br />
</span><span style="color:gray;">+ </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@alpha</span><span style="color:gray;">, (</span><span style="color:#434343;">@CommaPos </span><span style="color:gray;">+ </span><span style="color:black;">1</span><span style="color:gray;">), </span><span style="color:black;">20</span><span style="color:gray;">))<br />
</span><span style="color:blue;">END<br />
</span><span style="color:green;">-- Since we in this case don't want to set 0 if where is no numeric value, we set NULL to be safe<br />
</span><span style="color:blue;">IF </span><span style="color:gray;">(</span><span style="color:#434343;">@decimal </span><span style="color:blue;">= </span><span style="color:black;">0 </span><span style="color:gray;">AND </span><span style="color:#434343;">@ZeroExists </span><span style="color:blue;">= </span><span style="color:black;">0</span><span style="color:gray;">) </span><span style="color:blue;">BEGIN<br />
SET </span><span style="color:#434343;">@decimal </span><span style="color:blue;">= </span><span style="color:gray;">NULL<br />
</span><span style="color:blue;">END<br />
END<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;">If you run above SP as shown below it will work<br />
<code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@myRetVal </span><span style="color:blue;">DECIMAL</span><span style="color:gray;">(</span><span style="color:black;">14</span><span style="color:gray;">,</span><span style="color:black;">5</span><span style="color:gray;">)<br />
</span><span style="color:blue;">EXEC </span><span style="color:black;">[CleanDataFromAlpha] </span><span style="color:red;">'ABC355,88ghf'</span><span style="color:gray;">, </span><span style="color:#434343;">@myRetVal </span><span style="color:black;">OUTPUT<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@myRetVal </span><span style="color:black;">ReturnValue</span></code></p>
<pre style="text-align:justify;">ReturnValue
---------------------------------------
355.88000

(1 row(s) affected)</pre>
<p style="text-align:justify;">I once again want to thanks <strong><a href="http://blog.sqlauthority.com/2008/10/14/sql-server-get-numeric-value-from-alpha-numeric-string-udf-for-get-numeric-numbers-only/#comment-89217">Christofer</a></strong> for his excellent contribution.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<br />Filed under: <a href='http://blog.sqlauthority.com/category/tech/pinal-dave/'>Pinal Dave</a>, <a href='http://blog.sqlauthority.com/category/technology/sql/'>SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-authority/'>SQL Authority</a>, <a href='http://blog.sqlauthority.com/category/sql-function/'>SQL Function</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-query/'>SQL Query</a>, <a href='http://blog.sqlauthority.com/category/tech/sql-scripts/'>SQL Scripts</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-server/'>SQL Server</a>, <a href='http://blog.sqlauthority.com/category/sql-stored-procedure/'>SQL Stored Procedure</a>, <a href='http://blog.sqlauthority.com/category/sql-string/'>SQL String</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-tips-and-tricks/'>SQL Tips and Tricks</a>, <a href='http://blog.sqlauthority.com/category/technology/t-sql/'>T SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/'>Technology</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/10366/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/10366/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/10366/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/10366/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/10366/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/10366/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/10366/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/10366/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/10366/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/10366/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/10366/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/10366/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/10366/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/10366/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=10366&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2010/09/25/sql-server-get-numeric-value-from-alpha-numeric-string-get-numbers-only/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER – Function to Retrieve First Word of Sentence – String Operation</title>
		<link>http://blog.sqlauthority.com/2010/08/20/sql-server-function-to-retrieve-first-word-of-sentence-string-operation/</link>
		<comments>http://blog.sqlauthority.com/2010/08/20/sql-server-function-to-retrieve-first-word-of-sentence-string-operation/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 01:30:08 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9873</guid>
		<description><![CDATA[I have sent of function library where I store all the UDF I have ever written. Recently I received email from my friend requesting if I have UDF which manipulate string and returns only very first word of the statement. Well, I realize that I do not have such a script at all. I found [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=9873&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">I have sent of function library where I store all the UDF I have ever written. Recently I received email from my friend requesting if I have UDF which manipulate string and returns only very first word of the statement. Well, I realize that I do not have such a script at all. I found myself writing down this similar script after long time. Let me know if you know any other better script to do the same task.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@StringVar </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">100</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@StringVar </span><span style="color:blue;">= </span><span style="color:red;">' anything '<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">CASE </span><span style="color:blue;">CHARINDEX</span><span style="color:gray;">(</span><span style="color:red;">' '</span><span style="color:gray;">, </span><span style="color:magenta;">LTRIM</span><span style="color:gray;">(</span><span style="color:#434343;">@StringVar</span><span style="color:gray;">), </span><span style="color:black;">1</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">0 </span><span style="color:blue;">THEN </span><span style="color:magenta;">LTRIM</span><span style="color:gray;">(</span><span style="color:#434343;">@StringVar</span><span style="color:gray;">)<br />
</span><span style="color:blue;">ELSE </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:magenta;">LTRIM</span><span style="color:gray;">(</span><span style="color:#434343;">@StringVar</span><span style="color:gray;">), </span><span style="color:black;">1</span><span style="color:gray;">, </span><span style="color:blue;">CHARINDEX</span><span style="color:gray;">(</span><span style="color:red;">' '</span><span style="color:gray;">,</span><span style="color:magenta;">LTRIM</span><span style="color:gray;">(</span><span style="color:#434343;">@StringVar</span><span style="color:gray;">), </span><span style="color:black;">1</span><span style="color:gray;">) - </span><span style="color:black;">1</span><span style="color:gray;">)<br />
</span><span style="color:blue;">END </span><span style="color:black;">FirstWordofSentence<br />
</span></code></p>
<p style="text-align:justify;">Above script can be converted to User Defined Function which you can later use in SELECT statement as well. Here is how you can convert it to UDF and use it afterwords.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">GetFirstWord </span><span style="color:gray;">(</span><span style="color:#434343;">@StringVar </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:magenta;">MAX</span><span style="color:gray;">))<br />
</span><span style="color:blue;">RETURNS VARCHAR</span><span style="color:gray;">(</span><span style="color:magenta;">MAX</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
BEGIN<br />
DECLARE </span><span style="color:#434343;">@rtStringVar </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:magenta;">MAX</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@rtStringVar </span><span style="color:blue;">= </span><span style="color:magenta;">CASE </span><span style="color:blue;">CHARINDEX</span><span style="color:gray;">(</span><span style="color:red;">' '</span><span style="color:gray;">, </span><span style="color:magenta;">LTRIM</span><span style="color:gray;">(</span><span style="color:#434343;">@StringVar</span><span style="color:gray;">), </span><span style="color:black;">1</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">0 </span><span style="color:blue;">THEN </span><span style="color:magenta;">LTRIM</span><span style="color:gray;">(</span><span style="color:#434343;">@StringVar</span><span style="color:gray;">)<br />
</span><span style="color:blue;">ELSE </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:magenta;">LTRIM</span><span style="color:gray;">(</span><span style="color:#434343;">@StringVar</span><span style="color:gray;">), </span><span style="color:black;">1</span><span style="color:gray;">, </span><span style="color:blue;">CHARINDEX</span><span style="color:gray;">(</span><span style="color:red;">' '</span><span style="color:gray;">,</span><span style="color:magenta;">LTRIM</span><span style="color:gray;">(</span><span style="color:#434343;">@StringVar</span><span style="color:gray;">), </span><span style="color:black;">1</span><span style="color:gray;">) - </span><span style="color:black;">1</span><span style="color:gray;">)<br />
</span><span style="color:blue;">END<br />
RETURN </span><span style="color:#434343;">@rtStringVar<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">--Usage of Function<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">dbo.GetFirstWord </span><span style="color:gray;">(</span><span style="color:red;">''</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">FirstWordofSentence</span><span style="color:gray;">;<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">dbo.GetFirstWord </span><span style="color:gray;">(</span><span style="color:red;">' Space Before'</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">FirstWordofSentence</span><span style="color:gray;">;<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">dbo.GetFirstWord </span><span style="color:gray;">(</span><span style="color:red;">'Long Statement'</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">FirstWordofSentence</span><span style="color:gray;">;<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">dbo.GetFirstWord </span><span style="color:gray;">(</span><span style="color:red;">'SingleWord'</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">FirstWordofSentence</span><span style="color:gray;">;</span></code></p>
<p style="text-align:justify;">You can see in the resultset where it will find the very first word of the any sentence.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
<br />Filed under: <a href='http://blog.sqlauthority.com/category/technology/sql/'>SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-authority/'>SQL Authority</a>, <a href='http://blog.sqlauthority.com/category/sql-function/'>SQL Function</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-query/'>SQL Query</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-server/'>SQL Server</a>, <a href='http://blog.sqlauthority.com/category/sql-string/'>SQL String</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-tips-and-tricks/'>SQL Tips and Tricks</a>, <a href='http://blog.sqlauthority.com/category/technology/t-sql/'>T SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/'>Technology</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/9873/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/9873/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/9873/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/9873/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/9873/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/9873/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/9873/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/9873/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/9873/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/9873/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/9873/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/9873/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/9873/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/9873/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=9873&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2010/08/20/sql-server-function-to-retrieve-first-word-of-sentence-string-operation/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Finding the Occurrence of Character in String</title>
		<link>http://blog.sqlauthority.com/2010/08/16/sql-server-finding-the-occurrence-of-character-in-string/</link>
		<comments>http://blog.sqlauthority.com/2010/08/16/sql-server-finding-the-occurrence-of-character-in-string/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 01:30:13 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9907</guid>
		<description><![CDATA[This article is written in response to provide hint to TSQL Beginners Challenge 14. The challenge is about counting the number of occurrences of characters in the string. Here is quick method how you can count occurrence of character in any string. Here is quick example which provides you two different details. How many times [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=9907&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">This article is written in response to provide hint to <a href="http://beyondrelational.com/blogs/tcb/archive/2010/08/16/count-the-number-of-occurrences-of-characters-in-the-string.aspx?utm_source=sqlauthority&amp;utm_medium=challenge&amp;utm_campaign=sqlautohritytcb14" target="_blank">TSQL Beginners Challenge 14</a>. The challenge is about counting the number of occurrences of characters in the string. Here is quick method how you can count occurrence of character in any string.</p>
<p style="text-align:justify;">Here is quick example which provides you two different details.</p>
<ul style="text-align:justify;">
<li>How many times the character/word exists in string?</li>
<li>How many total characters exists in Occurrence?</li>
</ul>
<p style="text-align:justify;">Let us see following example and it will clearly explain it to you.</p>
<p style="text-align:left;"><code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@LongSentence </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:magenta;">MAX</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@FindSubString </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:magenta;">MAX</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@LongSentence </span><span style="color:blue;">= </span><span style="color:red;">'My Super Long String With Long Words'<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@FindSubString </span><span style="color:blue;">= </span><span style="color:red;">'long'<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">(</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:#434343;">@LongSentence</span><span style="color:gray;">) - </span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:magenta;">REPLACE</span><span style="color:gray;">(</span><span style="color:#434343;">@LongSentence</span><span style="color:gray;">, </span><span style="color:#434343;">@FindSubString</span><span style="color:gray;">, </span><span style="color:red;">''</span><span style="color:gray;">))) </span><span style="color:black;">CntReplacedChars</span><span style="color:gray;">,<br />
(</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:#434343;">@LongSentence</span><span style="color:gray;">) - </span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:magenta;">REPLACE</span><span style="color:gray;">(</span><span style="color:#434343;">@LongSentence</span><span style="color:gray;">, </span><span style="color:#434343;">@FindSubString</span><span style="color:gray;">, </span><span style="color:red;">''</span><span style="color:gray;">)))/</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:#434343;">@FindSubString</span><span style="color:gray;">) </span><span style="color:black;">CntOccuranceChars</span></code></p>
<p style="text-align:justify;">This will return following resultset.</p>
<pre style="text-align:justify;">CntReplacedChars     CntOccuranceChars
-------------------- --------------------
2                    2</pre>
<p style="text-align:justify;">If there is single word to find in the character, both the answer will be same. Here is the example of the same.</p>
<p style="text-align:left;"><code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@LongSentence </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:magenta;">MAX</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@FindSubString </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:magenta;">MAX</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@LongSentence </span><span style="color:blue;">= </span><span style="color:red;">'My Super Long String With Long Words'<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@FindSubString </span><span style="color:blue;">= </span><span style="color:red;">'o'<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">(</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:#434343;">@LongSentence</span><span style="color:gray;">) - </span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:magenta;">REPLACE</span><span style="color:gray;">(</span><span style="color:#434343;">@LongSentence</span><span style="color:gray;">, </span><span style="color:#434343;">@FindSubString</span><span style="color:gray;">, </span><span style="color:red;">''</span><span style="color:gray;">))) </span><span style="color:black;">CntReplacedChars</span><span style="color:gray;">,<br />
(</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:#434343;">@LongSentence</span><span style="color:gray;">) - </span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:magenta;">REPLACE</span><span style="color:gray;">(</span><span style="color:#434343;">@LongSentence</span><span style="color:gray;">, </span><span style="color:#434343;">@FindSubString</span><span style="color:gray;">, </span><span style="color:red;">''</span><span style="color:gray;">)))/</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:#434343;">@FindSubString</span><span style="color:gray;">) </span><span style="color:black;">CntOccuranceChars</span></code></p>
<p style="text-align:justify;">This will return following resultset.</p>
<pre style="text-align:justify;">CntReplacedChars     CntOccuranceChars
-------------------- --------------------
3                    3</pre>
<p style="text-align:justify;">I hope using this hint along with <strong><a href="http://blog.sqlauthority.com/2008/07/28/sql-server-simple-example-of-recursive-cte/" target="_blank">recursive CTE</a></strong> you will be able to solve the T-SQL Challenge. Additionally, make sure that your strings does not have leading or trailing empty spaces. If you have it, you may want to use LTRIM or RTRIM functions.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
<br />Filed under: <a href='http://blog.sqlauthority.com/category/tech/pinal-dave/'>Pinal Dave</a>, <a href='http://blog.sqlauthority.com/category/technology/sql/'>SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-authority/'>SQL Authority</a>, <a href='http://blog.sqlauthority.com/category/sql-function/'>SQL Function</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-query/'>SQL Query</a>, <a href='http://blog.sqlauthority.com/category/tech/sql-scripts/'>SQL Scripts</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-server/'>SQL Server</a>, <a href='http://blog.sqlauthority.com/category/sql-string/'>SQL String</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-tips-and-tricks/'>SQL Tips and Tricks</a>, <a href='http://blog.sqlauthority.com/category/technology/t-sql/'>T SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/'>Technology</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/9907/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/9907/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/9907/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/9907/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/9907/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/9907/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/9907/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/9907/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/9907/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/9907/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/9907/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/9907/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/9907/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/9907/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=9907&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2010/08/16/sql-server-finding-the-occurrence-of-character-in-string/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQLAuthority News &#8211; Converting a Delimited String of Values into Columns</title>
		<link>http://blog.sqlauthority.com/2010/02/10/sqlauthority-news-converting-a-delimited-string-of-values-into-columns/</link>
		<comments>http://blog.sqlauthority.com/2010/02/10/sqlauthority-news-converting-a-delimited-string-of-values-into-columns/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 01:30:05 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL XML]]></category>
		<category><![CDATA[SQLAuthority Website Review]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7965</guid>
		<description><![CDATA[This blog post is about two great bloggers and their excellent series of blog posts. It was quite unusual to see two bloggers posting articles that are supporting each other and constantly improving the articles to the next level. Two blogs which I am going to mention here are as follows: SELECT Blog FROM Brad.Schulz [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=7965&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">This blog post is about two great bloggers and their excellent series of blog posts. It was quite unusual to see two bloggers posting articles that are supporting each other and constantly improving the articles to the next level.</p>
<p style="text-align:justify;">Two blogs which I am going to mention here are as follows: <a href="http://bradsruminations.blogspot.com/" target="_blank"><strong>SELECT Blog FROM Brad.Schulz CROSS APPLY SQL.Server() &#8211; Brad Schulz</strong></a> and <a href="http://jahaines.blogspot.com/" target="_blank"><strong>Demystifying SQL Server &#8211; Adam Haines</strong></a>. Before continuing this blog post, I suggest you all to bookmark these blogs for future reference.</p>
<p style="text-align:justify;">The whole thing started when Adam tried to answer the question &#8220;How to transform a delimited values into columns?&#8221; on MSDN SQL Forum. Adam made the first blog post here <a href="http://jahaines.blogspot.com/2009/06/converting-delimited-string-of-values.html" target="_blank"><strong>http://jahaines.blogspot.com/2009/06/converting-delimited-string-of-values.html</strong></a> and then Brad and Adam bounced a few ideas off the wall. Then, Adam started his series on concatenating column values <a href="http://jahaines.blogspot.com/2009/06/concatenating-column-values-part-1.html" target="_blank">http://jahaines.blogspot.com/2009/06/concatenating-column-values-part-1.html</a>, and <a href="http://jahaines.blogspot.com/2009/07/concatenating-column-values-part-2.html" target="_blank">http://jahaines.blogspot.com/2009/07/concatenating-column-values-part-2.html</a>.  In part two of the series, Brad wanted to get a deeper understanding of why the results came out the way they did. Adam then started another series on unpacking or parsing out delimited characters, <a href="http://jahaines.blogspot.com/2009/11/splitting-delimited-string-part-1.html" target="_blank">http://jahaines.blogspot.com/2009/11/splitting-delimited-string-part-1.html</a> and here <a href="http://jahaines.blogspot.com/2009/12/splitting-delimited-string-part-2.html" target="_blank">http://jahaines.blogspot.com/2009/12/splitting-delimited-string-part-2.html</a>.  From here, Brad started digging even deeper into the internals of the XML method. Brad has a comprehensive list of the back and forth on this post, <a href="http://bradsruminations.blogspot.com/2009/12/delimited-string-tennis-anyone.html" target="_blank">http://bradsruminations.blogspot.com/2009/12/delimited-string-tennis-anyone.html</a> and a final post here <a href="http://bradsruminations.blogspot.com/2010/01/delimited-string-tennis-again-final.html" target="_blank"><strong>http://bradsruminations.blogspot.com/2010/01/delimited-string-tennis-again-final.html</strong></a>.</p>
<p style="text-align:justify;">The final outcome is that both the XML method and number table can perform equally, but the XML method has to be coded in a very particular way; otherwise performance will be horrendous. Also, the permanent number table shows consistently more performance than the inline number table; however, on smaller string sizes, the difference here is that most of the inline number tables require more CPU and RAM, whereas the permanent number table requires more IO. For an average developer, the number table solution is probably the easiest of the solutions to implement.</p>
<p style="text-align:justify;">Overall, I strongly suggest to go through the abovementioned posts; you will love it and become their fan. Please note these posts are very easy to understand and if you know a bit of XML only, you will still be able to understand them very well. The above description has been taken with proper consent of the Adam and Brad.</p>
<p style="text-align:justify;">Hats Off to you Guys! You guys inspire me and many SQL enthusiasts!</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<p style="text-align:justify;">
<br />Filed under: <a href='http://blog.sqlauthority.com/category/tech/pinal-dave/'>Pinal Dave</a>, <a href='http://blog.sqlauthority.com/category/technology/sql/'>SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-authority/'>SQL Authority</a>, <a href='http://blog.sqlauthority.com/category/sql-function/'>SQL Function</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-query/'>SQL Query</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-server/'>SQL Server</a>, <a href='http://blog.sqlauthority.com/category/sql-string/'>SQL String</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-tips-and-tricks/'>SQL Tips and Tricks</a>, <a href='http://blog.sqlauthority.com/category/sql-xml/'>SQL XML</a>, <a href='http://blog.sqlauthority.com/category/sqlauthority/sqlauthority-website-review/'>SQLAuthority Website Review</a>, <a href='http://blog.sqlauthority.com/category/technology/t-sql/'>T SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/'>Technology</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7965/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7965/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7965/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7965/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/7965/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/7965/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/7965/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/7965/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7965/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7965/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7965/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7965/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7965/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7965/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=7965&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2010/02/10/sqlauthority-news-converting-a-delimited-string-of-values-into-columns/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Comma Separated Values (CSV) from Table Column &#8211; Part 2</title>
		<link>http://blog.sqlauthority.com/2009/12/21/sql-server-comma-separated-values-csv-from-table-column-part-2/</link>
		<comments>http://blog.sqlauthority.com/2009/12/21/sql-server-comma-separated-values-csv-from-table-column-part-2/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 01:30:58 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL XML]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7575</guid>
		<description><![CDATA[In my earlier post, I wrote about how one can use XML to convert table to string SQL SERVER – Comma Separated Values (CSV) from Table Column. The same article is also published on channel 9 SQLAuthority News – Featured on Channel 9. One of the very interesting points that was discussed on show was [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=7575&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my earlier post, I wrote about how one can use XML to convert table to string <a href="http://blog.sqlauthority.com/2009/11/25/sql-server-comma-separated-values-csv-from-table-column/" target="_blank"><strong>SQL SERVER – Comma Separated Values (CSV) from Table Column</strong></a>. The same article is also published on channel 9 <a href="http://blog.sqlauthority.com/2009/12/12/sqlauthority-news-featured-on-channel-9/" target="_blank"><strong>SQLAuthority News – Featured on Channel 9</strong></a>. One of the very interesting points that was discussed on show was about the usage of function SUBSTRING. I found the following point very valid: SUBSTRING usage limits the length of the XML to be used.</p>
<p>I have re-written the same function with function STUFF, and it removes any limit imposed on the script.</p>
<p><pre class="brush: sql; gutter: false;">
USE AdventureWorks
GO
-- Check Table Column
SELECT [Name]
FROM HumanResources.Shift
GO
-- Get CSV values
SELECT STUFF(
(SELECT ',' + s.Name
FROM HumanResources.Shift s
ORDER BY s.Name
FOR XML PATH('')),1,1,'') AS CSV
GO
</pre></p>
<p>Do let me know your thoughts on the same.</p>
<p><img class="alignnone" src="http://www.pinaldave.com/bimg/stuffsub.jpg" alt="" width="325" height="469" /></p>
<p>Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<br />Posted in Database, Pinal Dave, SQL, SQL Authority, SQL Query, SQL Scripts, SQL Server, SQL String, SQL Tips and Tricks, SQL XML, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/7575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/7575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/7575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/7575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7575/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=7575&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/12/21/sql-server-comma-separated-values-csv-from-table-column-part-2/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/stuffsub.jpg" medium="image" />
	</item>
		<item>
		<title>SQLAuthority News &#8211; Featured on Channel 9</title>
		<link>http://blog.sqlauthority.com/2009/12/12/sqlauthority-news-featured-on-channel-9/</link>
		<comments>http://blog.sqlauthority.com/2009/12/12/sqlauthority-news-featured-on-channel-9/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 01:30:52 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[About Me]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLAuthority News]]></category>
		<category><![CDATA[SQLAuthority Website Review]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7557</guid>
		<description><![CDATA[This blog was featured on Channel 9 MSDN over here : TWC9: Scott Hanselman, Jon Galloway, Bing, parallel unit tests, more. I was very proud that this blog was discussed for more than 5 mins (from min 18 to min 23) on my favorite online show. Scott Hanselman, Jon Galloway along with Dan Fernandez make [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=7557&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">This blog was featured on Channel 9 MSDN over here : <a href="http://channel9.msdn.com/shows/This+Week+On+Channel+9/TWC9-with-Scott-Hanselman-and-John-Galloway/" target="_blank">TWC9: Scott Hanselman, Jon Galloway, Bing, parallel unit tests, more</a>. I was very proud that this blog was discussed for more than 5 mins (from min 18 to min 23) on my favorite online show. Scott Hanselman, Jon Galloway along with Dan Fernandez make this show very live and very very entertaining.</p>
<p style="text-align:justify;">The article which was featured in the show is <strong><a href="http://blog.sqlauthority.com/2009/11/25/sql-server-comma-separated-values-csv-from-table-column/" target="_blank">SQL SERVER – Comma Separated Values (CSV) from Table Column</a></strong>.</p>
<p style="text-align:justify;">Here are few screenshot from the show.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/channel9_1.jpg" alt="" width="500" height="381" /></p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/channel9_2.jpg" alt="" width="500" height="375" /></p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/channel9_3.jpg" alt="" width="500" height="365" /></p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/channel9_4.jpg" alt="" width="425" height="426" /></p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (<a href="http://blog.sqlauthority.com/" target="_blank">http://blog.SQLAuthority.com</a>)</strong></p>
<p style="text-align:justify;">
<br />Posted in About Me, Database, Pinal Dave, SQL, SQL Authority, SQL Query, SQL Server, SQL String, SQL Tips and Tricks, SQLAuthority News, SQLAuthority Website Review, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/7557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/7557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/7557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/7557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7557/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=7557&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/12/12/sqlauthority-news-featured-on-channel-9/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/channel9_1.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/channel9_2.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/channel9_3.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/channel9_4.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Remove Duplicate Entry from Comma Delimited String &#8211; UDF</title>
		<link>http://blog.sqlauthority.com/2009/01/15/sql-server-remove-duplicate-entry-from-comma-delimited-string-udf/</link>
		<comments>http://blog.sqlauthority.com/2009/01/15/sql-server-remove-duplicate-entry-from-comma-delimited-string-udf/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 01:30:44 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2035</guid>
		<description><![CDATA[I love reader&#8217;s contribution this blog as that brings variety in articles. I encourage my readers to provide their contribution and I will publish then with their name. Blog Reader Ashish Jain has posted very simple script which will remove duplicate entry from comma delimited string. User Defined Function has very simple logic behind it. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=2035&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">I love reader&#8217;s contribution this blog as that brings variety in articles. I encourage my readers to provide their contribution and I will publish then with their name.</p>
<p style="text-align:justify;">Blog Reader <a href="http://blog.sqlauthority.com/2007/12/30/sql-server-remove-duplicate-characters-from-a-string/#comment-45626" target="_blank"><strong>Ashish Jain</strong></a> has posted very simple script which will remove duplicate entry from comma delimited string. User Defined Function has very simple logic behind it. It takes comma delimited string and then converts it to table and runs DISTINCT operation on the table. DISTINCT operation removes duplicate value. After that it converts the table again into the string and it can be used.</p>
<p style="text-align:justify;">I have modified original contribution from Ashish so now it completely covers the subject intended to cover. I would suggest that this UDF should be kept handy to perform this tedious task easily.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">dbo.DistinctList<br />
</span><span style="color:gray;">(<br />
</span><span style="color:#434343;">@List </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">),<br />
</span><span style="color:#434343;">@Delim </span><span style="color:blue;">CHAR<br />
</span><span style="color:gray;">)<br />
</span><span style="color:blue;">RETURNS<br />
VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
BEGIN<br />
DECLARE </span><span style="color:#434343;">@ParsedList </span><span style="color:blue;">TABLE<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">Item </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">)<br />
)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@list1 </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">), </span><span style="color:#434343;">@Pos </span><span style="color:blue;">INT</span><span style="color:gray;">, </span><span style="color:#434343;">@rList </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@list </span><span style="color:blue;">= </span><span style="color:magenta;">LTRIM</span><span style="color:gray;">(</span><span style="color:magenta;">RTRIM</span><span style="color:gray;">(</span><span style="color:#434343;">@list</span><span style="color:gray;">)) + </span><span style="color:#434343;">@Delim<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@pos </span><span style="color:blue;">= CHARINDEX</span><span style="color:gray;">(</span><span style="color:#434343;">@delim</span><span style="color:gray;">, </span><span style="color:#434343;">@list</span><span style="color:gray;">, </span><span style="color:black;">1</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHILE </span><span style="color:#434343;">@pos </span><span style="color:gray;">&gt; </span><span style="color:black;">0<br />
</span><span style="color:blue;">BEGIN<br />
SET </span><span style="color:#434343;">@list1 </span><span style="color:blue;">= </span><span style="color:magenta;">LTRIM</span><span style="color:gray;">(</span><span style="color:magenta;">RTRIM</span><span style="color:gray;">(</span><span style="color:magenta;">LEFT</span><span style="color:gray;">(</span><span style="color:#434343;">@list</span><span style="color:gray;">, </span><span style="color:#434343;">@pos </span><span style="color:gray;">- </span><span style="color:black;">1</span><span style="color:gray;">)))<br />
</span><span style="color:blue;">IF </span><span style="color:#434343;">@list1 </span><span style="color:gray;">&lt;&gt; </span><span style="color:red;">''<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:#434343;">@ParsedList </span><span style="color:blue;">VALUES </span><span style="color:gray;">(</span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:#434343;">@list1 </span><span style="color:blue;">AS VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">)))<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@list </span><span style="color:blue;">= </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@list</span><span style="color:gray;">, </span><span style="color:#434343;">@pos</span><span style="color:gray;">+</span><span style="color:black;">1</span><span style="color:gray;">, </span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:#434343;">@list</span><span style="color:gray;">))<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@pos </span><span style="color:blue;">= CHARINDEX</span><span style="color:gray;">(</span><span style="color:#434343;">@delim</span><span style="color:gray;">, </span><span style="color:#434343;">@list</span><span style="color:gray;">, </span><span style="color:black;">1</span><span style="color:gray;">)<br />
</span><span style="color:blue;">END<br />
SELECT </span><span style="color:#434343;">@rlist </span><span style="color:blue;">= </span><span style="color:magenta;">COALESCE</span><span style="color:gray;">(</span><span style="color:#434343;">@rlist</span><span style="color:gray;">+</span><span style="color:red;">','</span><span style="color:gray;">,</span><span style="color:red;">''</span><span style="color:gray;">) + </span><span style="color:black;">item<br />
</span><span style="color:blue;">FROM </span><span style="color:gray;">(</span><span style="color:blue;">SELECT DISTINCT </span><span style="color:black;">Item </span><span style="color:blue;">FROM </span><span style="color:#434343;">@ParsedList</span><span style="color:gray;">) </span><span style="color:black;">t<br />
</span><span style="color:blue;">RETURN </span><span style="color:#434343;">@rlist<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">dbo.DistinctList</span><span style="color:gray;">(</span><span style="color:red;">'342,34,456,34,3454,456,aa,bb,cc,aa'</span><span style="color:gray;">,</span><span style="color:red;">','</span><span style="color:gray;">) </span><span style="color:black;">DistinctList<br />
GO</span></code>
</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/distinctstring.jpg" alt="" width="500" height="569" /></p>
<p style="text-align:justify;">I encourage my readers to send their contribution as well so I can include their contribution as well.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (<a href="http://blog.SQLAuthority.com" target="_blank">http://blog.SQLAuthority.com</a>)</strong></p>
<br />Posted in Pinal Dave, Readers Contribution, SQL, SQL Authority, SQL Function, SQL Query, SQL Scripts, SQL Server, SQL String, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/2035/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/2035/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/2035/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/2035/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/2035/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/2035/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/2035/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/2035/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/2035/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/2035/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/2035/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/2035/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/2035/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/2035/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=2035&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/01/15/sql-server-remove-duplicate-entry-from-comma-delimited-string-udf/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/distinctstring.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Get Numeric Value From Alpha Numeric String &#8211; UDF for Get Numeric Numbers Only</title>
		<link>http://blog.sqlauthority.com/2008/10/14/sql-server-get-numeric-value-from-alpha-numeric-string-udf-for-get-numeric-numbers-only/</link>
		<comments>http://blog.sqlauthority.com/2008/10/14/sql-server-get-numeric-value-from-alpha-numeric-string-udf-for-get-numeric-numbers-only/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 01:30:40 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1360</guid>
		<description><![CDATA[SQL is great with String operations. Many times, I use T-SQL to do my string operation. Let us see User Defined Function, which I wrote few days ago, which will return only Numeric values from AlphaNumeric values. CREATE FUNCTION dbo.udf_GetNumeric (@strAlphaNumeric VARCHAR(256)) RETURNS VARCHAR(256) AS BEGIN DECLARE @intAlpha INT SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric) BEGIN WHILE @intAlpha [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=1360&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">SQL is great with String operations. Many times, I use T-SQL to do my string operation. Let us see User Defined Function, which I wrote few days ago, which will return only Numeric values from AlphaNumeric values.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">dbo.udf_GetNumeric<br />
</span><span style="color:gray;">(</span><span style="color:#434343;">@strAlphaNumeric </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">256</span><span style="color:gray;">))<br />
</span><span style="color:blue;">RETURNS VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">256</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
BEGIN<br />
DECLARE </span><span style="color:#434343;">@intAlpha </span><span style="color:blue;">INT<br />
SET </span><span style="color:#434343;">@intAlpha </span><span style="color:blue;">= </span><span style="color:magenta;">PATINDEX</span><span style="color:gray;">(</span><span style="color:red;">'%[^0-9]%'</span><span style="color:gray;">, </span><span style="color:#434343;">@strAlphaNumeric</span><span style="color:gray;">)<br />
</span><span style="color:blue;">BEGIN<br />
WHILE </span><span style="color:#434343;">@intAlpha </span><span style="color:gray;">&gt; </span><span style="color:black;">0<br />
</span><span style="color:blue;">BEGIN<br />
SET </span><span style="color:#434343;">@strAlphaNumeric </span><span style="color:blue;">= </span><span style="color:magenta;">STUFF</span><span style="color:gray;">(</span><span style="color:#434343;">@strAlphaNumeric</span><span style="color:gray;">, </span><span style="color:#434343;">@intAlpha</span><span style="color:gray;">, </span><span style="color:black;">1</span><span style="color:gray;">, </span><span style="color:red;">'' </span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@intAlpha </span><span style="color:blue;">= </span><span style="color:magenta;">PATINDEX</span><span style="color:gray;">(</span><span style="color:red;">'%[^0-9]%'</span><span style="color:gray;">, </span><span style="color:#434343;">@strAlphaNumeric </span><span style="color:gray;">)<br />
</span><span style="color:blue;">END<br />
END<br />
RETURN </span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:#434343;">@strAlphaNumeric</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">)<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">/* Run the UDF with different test values */<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">dbo.udf_GetNumeric</span><span style="color:gray;">(</span><span style="color:red;">''</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:red;">'EmptyString'</span><span style="color:gray;">;<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">dbo.udf_GetNumeric</span><span style="color:gray;">(</span><span style="color:red;">'asdf1234a1s2d3f4@@@'</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:red;">'asdf1234a1s2d3f4@@@'</span><span style="color:gray;">;<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">dbo.udf_GetNumeric</span><span style="color:gray;">(</span><span style="color:red;">'123456'</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:red;">'123456'</span><span style="color:gray;">;<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">dbo.udf_GetNumeric</span><span style="color:gray;">(</span><span style="color:red;">'asdf'</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:red;">'asdf'</span><span style="color:gray;">;<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">dbo.udf_GetNumeric</span><span style="color:gray;">(NULL) </span><span style="color:blue;">AS </span><span style="color:red;">'NULL'</span><span style="color:gray;">;<br />
</span><span style="color:black;">GO </span></code>
</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/parseint.gif" alt="" width="297" height="383" /></p>
<p style="text-align:justify;">As result of above script self explainary, I will be not describing it in detail. If you use any alternative method to do the same task, please let me know.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<br />Posted in Pinal Dave, SQL, SQL Authority, SQL Function, SQL Query, SQL Scripts, SQL Server, SQL String, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/1360/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/1360/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/1360/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/1360/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/1360/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/1360/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/1360/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/1360/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/1360/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/1360/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/1360/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/1360/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/1360/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/1360/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=1360&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/10/14/sql-server-get-numeric-value-from-alpha-numeric-string-udf-for-get-numeric-numbers-only/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/parseint.gif" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; 2008 &#8211; Enhenced TRIM() Function &#8211; Remove Trailing Spaces, Leading Spaces, White Space, Tabs, Carriage Returns, Line Feeds</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/</link>
		<comments>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/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 01:30:54 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Utility]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1346</guid>
		<description><![CDATA[After reading my article SQL SERVER &#8211; 2008 &#8211; TRIM() Function &#8211; User Defined Function, I have received email and comments where user are asking if it is possible to remove trailing spaces, leading spaces, white space, tabs, carriage returns, line feeds etc. I found following script posted by Russ and Erik. It is modified [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=1346&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">After reading my article <strong><a href="http://blog.sqlauthority.com/2008/10/09/sql-server-2008-trim-function-user-defined-function/" target="_blank">SQL SERVER &#8211; 2008 &#8211; TRIM() Function &#8211; User Defined Function</a></strong>, I have received email and comments where user are asking if it is possible to remove trailing spaces, leading spaces, white space, tabs, carriage returns, line feeds etc.</p>
<p style="text-align:justify;">I found following script posted by <a href="http://blog.sqlauthority.com/2007/04/24/sql-server-trim-function-udf-trim/#comment-35417" target="_blank">Russ </a>and <a href="http://blog.sqlauthority.com/2007/04/24/sql-server-trim-function-udf-trim/#comment-42900" target="_blank">Erik</a>. It is modified a bit from original script.</p>
<p><code style="font-size:12px;"><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">dbo.LTrimX</span><span style="color:gray;">(</span><span style="color:#434343;">@str </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">)) </span><span style="color:blue;">RETURNS VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
BEGIN<br />
DECLARE </span><span style="color:#434343;">@trimchars </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@trimchars </span><span style="color:blue;">= CHAR</span><span style="color:gray;">(</span><span style="color:black;">9</span><span style="color:gray;">)+</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">)+</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">13</span><span style="color:gray;">)+</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">32</span><span style="color:gray;">)<br />
</span><span style="color:blue;">IF </span><span style="color:#434343;">@str </span><span style="color:gray;">LIKE </span><span style="color:red;">'[' </span><span style="color:gray;">+ </span><span style="color:#434343;">@trimchars </span><span style="color:gray;">+ </span><span style="color:red;">']%' </span><span style="color:blue;">SET </span><span style="color:#434343;">@str </span><span style="color:blue;">= </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@str</span><span style="color:gray;">, </span><span style="color:magenta;">PATINDEX</span><span style="color:gray;">(</span><span style="color:red;">'%[^' </span><span style="color:gray;">+ </span><span style="color:#434343;">@trimchars </span><span style="color:gray;">+ </span><span style="color:red;">']%'</span><span style="color:gray;">, </span><span style="color:#434343;">@str</span><span style="color:gray;">), </span><span style="color:black;">8000</span><span style="color:gray;">)<br />
</span><span style="color:blue;">RETURN </span><span style="color:#434343;">@str<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">dbo.RTrimX</span><span style="color:gray;">(</span><span style="color:#434343;">@str </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">)) </span><span style="color:blue;">RETURNS VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
BEGIN<br />
DECLARE </span><span style="color:#434343;">@trimchars </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@trimchars </span><span style="color:blue;">= CHAR</span><span style="color:gray;">(</span><span style="color:black;">9</span><span style="color:gray;">)+</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">)+</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">13</span><span style="color:gray;">)+</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">32</span><span style="color:gray;">)<br />
</span><span style="color:blue;">IF </span><span style="color:#434343;">@str </span><span style="color:gray;">LIKE </span><span style="color:red;">'%[' </span><span style="color:gray;">+ </span><span style="color:#434343;">@trimchars </span><span style="color:gray;">+ </span><span style="color:red;">']'<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@str </span><span style="color:blue;">= </span><span style="color:magenta;">REVERSE</span><span style="color:gray;">(</span><span style="color:black;">dbo.LTrimX</span><span style="color:gray;">(</span><span style="color:magenta;">REVERSE</span><span style="color:gray;">(</span><span style="color:#434343;">@str</span><span style="color:gray;">)))<br />
</span><span style="color:blue;">RETURN </span><span style="color:#434343;">@str<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">dbo.TrimX</span><span style="color:gray;">(</span><span style="color:#434343;">@str </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">)) </span><span style="color:blue;">RETURNS VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
BEGIN<br />
RETURN </span><span style="color:black;">dbo.LTrimX</span><span style="color:gray;">(</span><span style="color:black;">dbo.RTrimX</span><span style="color:gray;">(</span><span style="color:#434343;">@str</span><span style="color:gray;">))<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">/* Run the created function */<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">dbo.TRIMX</span><span style="color:gray;">(</span><span style="color:red;">'         word leading trailing spaces           '</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:red;">'TrimmedWord'<br />
</span><span style="color:black;">GO </span></code></p>
<p style="text-align:justify;">Running above function will give you result where there is no white spaces or any other while space like chars.</p>
<p style="text-align:justify;">Let me know what you think about this and if this can be improved further.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<br />Posted in Pinal Dave, SQL, SQL Authority, SQL Function, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL String, SQL Tips and Tricks, SQL Utility, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/1346/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=1346&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>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/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Remove Duplicate Characters From a String</title>
		<link>http://blog.sqlauthority.com/2007/12/30/sql-server-remove-duplicate-characters-from-a-string/</link>
		<comments>http://blog.sqlauthority.com/2007/12/30/sql-server-remove-duplicate-characters-from-a-string/#comments</comments>
		<pubDate>Sun, 30 Dec 2007 01:30:57 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/30/sql-server-remove-duplicate-characters-from-a-string/</guid>
		<description><![CDATA[Follow up of my previous article of Remove Duplicate Chars From String here is another great article written by Madhivanan where similar solution is suggested with alternate method of Number table approach. Check out Remove duplicate characters from a string Reference : Pinal Dave (http://blog.SQLAuthority.com)<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=458&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Follow up of my previous article of <a href="http://blog.sqlauthority.com/2007/12/05/sql-server-udf-remove-duplicate-chars-from-string/">Remove Duplicate Chars From String</a> here is another great article written by <a href="http://blog.sqlauthority.com/2007/12/05/sql-server-udf-remove-duplicate-chars-from-string/" target="_blank">Madhivanan</a> where similar solution is suggested with alternate method of Number table approach. Check out <a href="http://sqlserver-qa.net/blogs/t-sql/archive/2007/12/29/3070.aspx" target="_blank">Remove duplicate characters from a string</a></p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/458/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/458/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/458/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/458/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/458/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/458/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/458/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/458/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/458/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/458/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/458/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/458/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/458/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/458/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/458/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/458/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=458&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/12/30/sql-server-remove-duplicate-characters-from-a-string/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Do Not Store Images in Database &#8211; Store Location of Images (URL)</title>
		<link>http://blog.sqlauthority.com/2007/12/13/sql-server-do-not-store-images-in-database-store-location-of-images-url/</link>
		<comments>http://blog.sqlauthority.com/2007/12/13/sql-server-do-not-store-images-in-database-store-location-of-images-url/#comments</comments>
		<pubDate>Thu, 13 Dec 2007 01:30:56 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Interview Questions and Answers]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/13/sql-server-do-not-store-images-in-database-store-location-of-images-url/</guid>
		<description><![CDATA[Just a day ago I received phone call from my friend in Bangalore. He asked me What do I think of storing images in database and what kind of datatype he should use? I have very strong opinion about this issue. I suggest to store the location of the images in the database using VARCHAR [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=437&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Just a day ago I received phone call from my friend in Bangalore. He asked me</p>
<p style="text-align:justify;"><strong>What do I think of storing images in database and what kind of datatype he should use?</strong></p>
<p style="text-align:justify;">I have very strong opinion about this issue.</p>
<p style="text-align:justify;"><strong>I suggest to store the location of the images in the database using VARCHAR datatype instead of any BLOB or other binary datatype. </strong></p>
<p style="text-align:justify;">Storing the database location reduces the size of database greatly as well updating or replacing the image are much simpler as it is just an file operation instead of massive update/insert/delete in database.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/437/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/437/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/437/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/437/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/437/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/437/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/437/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/437/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/437/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/437/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/437/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/437/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/437/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/437/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/437/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/437/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=437&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/12/13/sql-server-do-not-store-images-in-database-store-location-of-images-url/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; UDF &#8211; Remove Duplicate Chars From String</title>
		<link>http://blog.sqlauthority.com/2007/12/05/sql-server-udf-remove-duplicate-chars-from-string/</link>
		<comments>http://blog.sqlauthority.com/2007/12/05/sql-server-udf-remove-duplicate-chars-from-string/#comments</comments>
		<pubDate>Wed, 05 Dec 2007 01:30:07 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Duplicate Records]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/05/sql-server-udf-remove-duplicate-chars-from-string/</guid>
		<description><![CDATA[Few days ago, I received following wonderful UDF from one of this blog reader. This UDF is written for specific purpose of removing duplicate chars string from one large string. Virendra Chauhan, author of this UDF is working as DBA in Lutheran Health Network. CREATE FUNCTION dbo.REMOVE_DUPLICATE_INSTR (@datalen_tocheck INT,@string VARCHAR(255)) RETURNS VARCHAR(255) AS BEGIN DECLARE [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=429&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Few days ago, I received following wonderful UDF from one of this blog reader. This UDF is written for specific purpose of removing duplicate chars string from one large string. <strong>Virendra Chauhan</strong>, author of this UDF is working as DBA in Lutheran Health Network.</p>
<p><code style="font-size:12px;"><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">dbo.REMOVE_DUPLICATE_INSTR<br />
</span><span style="color:gray;">(</span><span style="color:#434343;">@datalen_tocheck </span><span style="color:blue;">INT</span><span style="color:gray;">,</span><span style="color:#434343;">@string </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">255</span><span style="color:gray;">))<br />
</span><span style="color:blue;">RETURNS VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">255</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
BEGIN<br />
DECLARE </span><span style="color:#434343;">@str </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">255</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@count </span><span style="color:blue;">INT<br />
DECLARE </span><span style="color:#434343;">@start </span><span style="color:blue;">INT<br />
DECLARE </span><span style="color:#434343;">@result </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">255</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@end </span><span style="color:blue;">INT<br />
SET </span><span style="color:#434343;">@start</span><span style="color:blue;">=</span><span style="color:black;">1<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@end</span><span style="color:blue;">=</span><span style="color:#434343;">@datalen_tocheck<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@count</span><span style="color:blue;">=</span><span style="color:#434343;">@datalen_tocheck<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@str </span><span style="color:blue;">= </span><span style="color:#434343;">@string<br />
</span><span style="color:blue;">WHILE </span><span style="color:gray;">(</span><span style="color:#434343;">@count </span><span style="color:gray;">&lt;=</span><span style="color:black;">255</span><span style="color:gray;">)<br />
</span><span style="color:blue;">BEGIN<br />
IF </span><span style="color:gray;">(</span><span style="color:#434343;">@result </span><span style="color:blue;">IS </span><span style="color:gray;">NULL)<br />
</span><span style="color:blue;">BEGIN<br />
SET </span><span style="color:#434343;">@result</span><span style="color:blue;">=</span><span style="color:red;">''<br />
</span><span style="color:blue;">END<br />
SET </span><span style="color:#434343;">@result</span><span style="color:blue;">=</span><span style="color:#434343;">@result</span><span style="color:gray;">+</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@str</span><span style="color:gray;">,</span><span style="color:#434343;">@start</span><span style="color:gray;">,</span><span style="color:#434343;">@end</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@str</span><span style="color:blue;">=</span><span style="color:magenta;">REPLACE</span><span style="color:gray;">(</span><span style="color:#434343;">@str</span><span style="color:gray;">,</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@str</span><span style="color:gray;">,</span><span style="color:#434343;">@start</span><span style="color:gray;">,</span><span style="color:#434343;">@end</span><span style="color:gray;">),</span><span style="color:red;">''</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@count</span><span style="color:blue;">=</span><span style="color:#434343;">@count</span><span style="color:gray;">+</span><span style="color:#434343;">@datalen_tocheck<br />
</span><span style="color:blue;">END<br />
RETURN </span><span style="color:#434343;">@result<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO</span><span style="color:gray;">&gt;, </span><span style="color:black;">1</span><span style="color:gray;">)</span></code><br />
<strong>Usage:<br />
</strong><code style="font-size:12px;"><span style="color:blue;">SET </span><span style="color:black;">CONCAT_NULL_YIELDS_NULL </span><span style="color:blue;">OFF</span></code></p>
<p style="text-align:justify;">SELECT <span style="color:black;">dbo.Remove_duplicate_instr</span><span style="color:gray;">(&lt;</span><span style="color:blue;">CHAR</span><span style="color:black;">acter length </span><span style="color:blue;">OF </span><span style="color:black;">a</span></p>
<p style="text-align:justify;">duplicate <span style="color:magenta;">SUBSTRING </span><span style="color:gray;">&gt;,&lt;</span><span style="color:black;">string contain duplicate</span><span style="color:gray;">&gt;)</span><br />
<strong>Example:</strong><br />
To keep char set in a string unique and remove duplicate 3 char long string run this UDF as inline function.
</p>
<p class="Ih2E3d" style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SET </span><span style="color:black;">CONCAT_NULL_YIELDS_NULL </span><span style="color:blue;">OFF</span></code></p>
<p style="text-align:justify;">SELECT <span style="color:black;">dbo.Remove_duplicate_instr</span><span style="color:gray;">(</span><span style="color:black;">3</span><span style="color:gray;">,</span><span style="color:black;">f123456789123456456</span><br />
<strong>Resultset:</strong><br />
123456789</p>
<p>Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>), </strong>Virendra Chauhan (DBA)<strong></strong></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/429/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/429/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/429/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=429&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/12/05/sql-server-udf-remove-duplicate-chars-from-string/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; 2005 Collation Explanation and Translation &#8211; Part 2</title>
		<link>http://blog.sqlauthority.com/2007/07/14/sql-server-2005-collation-explanation-and-translation-part-2/</link>
		<comments>http://blog.sqlauthority.com/2007/07/14/sql-server-2005-collation-explanation-and-translation-part-2/#comments</comments>
		<pubDate>Sat, 14 Jul 2007 14:00:42 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[SQL Collation]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/07/14/sql-server-2005-collation-explanation-and-translation-part-2/</guid>
		<description><![CDATA[Following function return all the available collation of SQL Server 2005. My previous article about the SQL SERVER &#8211; 2005 Collation Explanation and Translation. SELECT * FROM sys.fn_HelpCollations() Result Set: (only few of 1011 records) Name Description Latin1_General_BIN Latin1-General, binary sort Latin1_General_BIN2 Latin1-General, binary code point comparison sort Latin1_General_CI_AI Latin1-General, case-insensitive, accent-insensitive, kanatype-insensitive, width-insensitive Latin1_General_CI_AI_WS [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=246&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Following function return all the available collation of SQL Server 2005. My previous article about the <a href="http://blog.sqlauthority.com/2007/04/24/sql-server-2005-collation-explanation-and-translation/">SQL SERVER &#8211; 2005 Collation Explanation and Translation.</a></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.</span><span style="color:darkred;">fn_HelpCollations</span><span style="color:gray;">()</span></code></p>
<p style="text-align:justify;"><strong>Result Set: (only few of 1011 records)</strong><br />
<strong>Name                                            Description</strong><br />
Latin1_General_BIN    Latin1-General, binary sort<br />
Latin1_General_BIN2    Latin1-General, binary code point comparison sort<br />
Latin1_General_CI_AI    Latin1-General, case-insensitive, accent-insensitive, kanatype-insensitive, width-insensitive<br />
Latin1_General_CI_AI_WS    Latin1-General, case-insensitive, accent-insensitive, kanatype-insensitive, width-sensitive<br />
Latin1_General_CI_AI_KS    Latin1-General, case-insensitive, accent-insensitive, kanatype-sensitive, width-insensitive<br />
Latin1_General_CI_AI_KS_WS    Latin1-General, case-insensitive, accent-insensitive, kanatype-sensitive, width-sensitive<br />
Latin1_General_CI_AS    Latin1-General, case-insensitive, accent-sensitive, kanatype-insensitive, width-insensitive<br />
Latin1_General_CI_AS_WS    Latin1-General, case-insensitive, accent-sensitive, kanatype-insensitive, width-sensitive<br />
Latin1_General_CI_AS_KS    Latin1-General, case-insensitive, accent-sensitive, kanatype-sensitive, width-insensitive<br />
Latin1_General_CI_AS_KS_WS    Latin1-General, case-insensitive, accent-sensitive, kanatype-sensitive, width-sensitive<br />
Latin1_General_CS_AI    Latin1-General, case-sensitive, accent-insensitive, kanatype-insensitive, width-insensitive<br />
Latin1_General_CS_AI_WS    Latin1-General, case-sensitive, accent-insensitive, kanatype-insensitive, width-sensitive<br />
Latin1_General_CS_AI_KS    Latin1-General, case-sensitive, accent-insensitive, kanatype-sensitive, width-insensitive<br />
Latin1_General_CS_AI_KS_WS    Latin1-General, case-sensitive, accent-insensitive, kanatype-sensitive, width-sensitive<br />
Latin1_General_CS_AS    Latin1-General, case-sensitive, accent-sensitive, kanatype-insensitive, width-insensitive<br />
Latin1_General_CS_AS_WS    Latin1-General, case-sensitive, accent-sensitive, kanatype-insensitive, width-sensitive<br />
Latin1_General_CS_AS_KS    Latin1-General, case-sensitive, accent-sensitive, kanatype-sensitive, width-insensitive<br />
Latin1_General_CS_AS_KS_WS    Latin1-General, case-sensitive, accent-sensitive, kanatype-sensitive, width-sensitive
</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/246/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/246/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/246/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=246&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/07/14/sql-server-2005-collation-explanation-and-translation-part-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Fix : Error : Server: Msg 131, Level 15, State 3, Line 1 The size () given to the type &#8216;varchar&#8217; exceeds the maximum allowed for any data type (8000)</title>
		<link>http://blog.sqlauthority.com/2007/06/30/sql-server-fix-error-server-msg-131-level-15-state-3-line-1-the-size-given-to-the-type-varchar-exceeds-the-maximum-allowed-for-any-data-type-8000/</link>
		<comments>http://blog.sqlauthority.com/2007/06/30/sql-server-fix-error-server-msg-131-level-15-state-3-line-1-the-size-given-to-the-type-varchar-exceeds-the-maximum-allowed-for-any-data-type-8000/#comments</comments>
		<pubDate>Sat, 30 Jun 2007 14:00:56 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Error Messages]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/30/sql-server-fix-error-server-msg-131-level-15-state-3-line-1-the-size-given-to-the-type-varchar-exceeds-the-maximum-allowed-for-any-data-type-8000/</guid>
		<description><![CDATA[Error: Server: Msg 131, Level 15, State 3, Line 1 The size () given to the type &#8216;varchar&#8217; exceeds the maximum allowed for any data type (8000) When the the length is specified in declaring a VARCHAR variable or column, the maximum length allowed is still 8000. Fix/WorkAround/Solution: Use either VARCHAR(8000) or VARCHAR(MAX) . VARCHAR(MAX) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=182&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Error:<br />
<span style="color:#ff0000;">Server: Msg 131, Level 15, State 3, Line 1 The size () given to the type &#8216;varchar&#8217; exceeds the maximum allowed for any data type (8000)</span>
</p>
<p style="text-align:justify;">When the the length is specified in declaring a VARCHAR variable or column, the maximum length allowed is still 8000.</p>
<p style="text-align:justify;"><strong>Fix/WorkAround/Solution:</strong> Use either VARCHAR(8000)  or VARCHAR(MAX) . VARCHAR(MAX) of SQL Server 2005 is replacement of TEXT of SQL Server 2000.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/182/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/182/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/182/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=182&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/06/30/sql-server-fix-error-server-msg-131-level-15-state-3-line-1-the-size-given-to-the-type-varchar-exceeds-the-maximum-allowed-for-any-data-type-8000/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Repeate String N Times Using String Function REPLICATE</title>
		<link>http://blog.sqlauthority.com/2007/06/25/sql-server-repeate-string-n-times-using-string-function-replicate/</link>
		<comments>http://blog.sqlauthority.com/2007/06/25/sql-server-repeate-string-n-times-using-string-function-replicate/#comments</comments>
		<pubDate>Mon, 25 Jun 2007 14:00:05 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/25/sql-server-repeate-string-n-times-using-string-function-replicate/</guid>
		<description><![CDATA[I came across this SQL String Function few days ago while searching for Database Replication. This is T-SQL Function and it repeats the string/character expression N number of times specified in the function. SELECT REPLICATE( ' http://www.SQLAuthority.com ' , 9 ) This repeats the string http://www.SQLAuthority.com to 9 times in result window. I think it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=176&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">I came across this SQL String Function few days ago while searching for Database Replication. This is T-SQL Function and it repeats the string/character expression N number of times specified in the function.</p>
<p><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:magenta;">REPLICATE</span><span style="color:gray;">( </span><span style="color:red;">' http://www.SQLAuthority.com ' </span><span style="color:gray;">, </span><span style="color:black;">9 </span><span style="color:gray;">)</span></code></p>
<p>This repeats the string <em>http://www.SQLAuthority.com</em> to 9 times in result window. I think it is fun utility to generate repeated text if ever required.</p>
<p style="text-align:justify;"><strong>Result Set:</strong><br />
http://www.SQLAuthority.com  http://www.SQLAuthority.com  http://www.SQLAuthority.com  http://www.SQLAuthority.com  http://www.SQLAuthority.com  http://www.SQLAuthority.com  http://www.SQLAuthority.com  http://www.SQLAuthority.com  http://www.SQLAuthority.com
</p>
<p style="text-align:justify;">(1 row(s) affected)</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong> , <a href="http://msdn2.microsoft.com/en-us/library/ms174383.aspx" target="_blank">BOL</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/176/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/176/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/176/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=176&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/06/25/sql-server-repeate-string-n-times-using-string-function-replicate/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; 2005 Row Overflow Data Explanation</title>
		<link>http://blog.sqlauthority.com/2007/06/23/sql-server-2005-row-overflow-data-explanation/</link>
		<comments>http://blog.sqlauthority.com/2007/06/23/sql-server-2005-row-overflow-data-explanation/#comments</comments>
		<pubDate>Sat, 23 Jun 2007 14:00:58 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/23/sql-server-2005-row-overflow-data-explanation/</guid>
		<description><![CDATA[In SQL Server 2000 and SQL Server 2005 a table can have a maximum of 8060 bytes per row. One of my fellow DBA said that he believed that SQL Server 2000 had that restriction but SQL Server 2005 does not have that restriction and it can have a row of 2GB. I totally agreed [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=213&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">In SQL Server 2000 and SQL Server 2005 a table can have a maximum of 8060 bytes per row. One  of my fellow DBA said that he believed that SQL Server 2000 had that  restriction but SQL Server 2005 does not have that restriction and it  can have a row of 2GB. I totally agreed with him but after we discussed  this problem in depth, we realized that there are more into it than only 8060 bytes limit.</p>
<p style="text-align:justify;">It is still true for SQL Server 2005 that a table can have maximum of 8060 bytes per row however the restriction has exclusions of few data types. CLR User Defined data-types as well as varchar, nvarchar, varbinary, sql_variants are not limited to bytes per row limitation. However, those data types have limitation that they can not be more than 8000 bytes individually. In SQL Server 2005 one table row can contain more than one varchar(8000) fields. One more thing, the exclusions have exclusions also the limit of each individual column max width of 8000 bytes does not apply to varchar(max), nvarchar(max), varbinary(max), text, image or xml data type columns. Though, sum of all other other kind of data type should be less than 8060 bytes. That means one table can not have three columns with char(4000) or 100K bit field columns.</p>
<p style="text-align:justify;"><span style="font-weight:bold;">In summary in SQL Server 2005</span></p>
<ul style="text-align:justify;">
<li>Table row can have more than 8060 bytes. (2GB Max)</li>
<li>varchar, nvarchar, varbinary, sql_variant, or CLR user-defined type columns can have max 8000 bytes.</li>
<li> varchar(max), nvarchar(max), varbinary(max), text, image or xml data type columns have no restrictions.</li>
<li>All the other data type columns (other than mentioned in above three points) width addition must be still under 8060 byte row limit.</li>
<li>Index can only be created which falls with-in 8060 byte row limit.</li>
</ul>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong> , <a href="http://msdn2.microsoft.com/en-us/library/ms186981.aspx" target="_blank">BOL</a>, <a href="http://blogs.msdn.com/chadboyd/archive/2007/02/24/row-sizes-exceeding-8060-bytes-in-sql-2005.aspx" target="_blank">SQL Stuff</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/213/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/213/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/213/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=213&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/06/23/sql-server-2005-row-overflow-data-explanation/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; 2005 &#8211; UDF &#8211; User Defined Function to Strip HTML &#8211; Parse HTML &#8211; No Regular Expression</title>
		<link>http://blog.sqlauthority.com/2007/06/16/sql-server-udf-user-defined-function-to-strip-html-parse-html-no-regular-expression/</link>
		<comments>http://blog.sqlauthority.com/2007/06/16/sql-server-udf-user-defined-function-to-strip-html-parse-html-no-regular-expression/#comments</comments>
		<pubDate>Sat, 16 Jun 2007 14:00:18 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/16/sql-server-udf-user-defined-function-to-strip-html-parse-html-no-regular-expression/</guid>
		<description><![CDATA[One of the developer at my company asked is it possible to parse HTML and retrieve only TEXT from it without using regular expression. He wanted to remove everything between &#60; and &#62; and keep only Text. I found question very interesting and quickly wrote UDF which does not use regular expression. Following UDF takes [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=204&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of the developer at my company asked is it possible to parse HTML and retrieve only TEXT from it without using regular expression. He wanted to remove everything between &lt; and &gt; and keep only Text. I found question very interesting and quickly wrote UDF which does not use regular expression.</p>
<p>Following UDF takes input as HTML and returns TEXT only. If there is any single quotes in HTML they should be replaced with two single quotes (not double quote) before it is passed as input to function.</p>
<p><code style="font-size:12px;"><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">[dbo].[udf_StripHTML]<br />
</span><span style="color:gray;">(</span><span style="color:#434343;">@HTMLText </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">))<br />
</span><span style="color:blue;">RETURNS VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
BEGIN<br />
DECLARE </span><span style="color:#434343;">@Start </span><span style="color:blue;">INT<br />
DECLARE </span><span style="color:#434343;">@End </span><span style="color:blue;">INT<br />
DECLARE </span><span style="color:#434343;">@Length </span><span style="color:blue;">INT<br />
SET </span><span style="color:#434343;">@Start </span><span style="color:blue;">= CHARINDEX</span><span style="color:gray;">(</span><span style="color:red;">'&lt;'</span><span style="color:gray;">,</span><span style="color:#434343;">@HTMLText</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@End </span><span style="color:blue;">= CHARINDEX</span><span style="color:gray;">(</span><span style="color:red;">'&gt;'</span><span style="color:gray;">,</span><span style="color:#434343;">@HTMLText</span><span style="color:gray;">,</span><span style="color:blue;">CHARINDEX</span><span style="color:gray;">(</span><span style="color:red;">'&lt;'</span><span style="color:gray;">,</span><span style="color:#434343;">@HTMLText</span><span style="color:gray;">))<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@Length </span><span style="color:blue;">= </span><span style="color:gray;">(</span><span style="color:#434343;">@End </span><span style="color:gray;">- </span><span style="color:#434343;">@Start</span><span style="color:gray;">) + </span><span style="color:black;">1<br />
</span><span style="color:blue;">WHILE </span><span style="color:#434343;">@Start </span><span style="color:gray;">&gt; </span><span style="color:black;">0<br />
</span><span style="color:gray;">AND </span><span style="color:#434343;">@End </span><span style="color:gray;">&gt; </span><span style="color:black;">0<br />
</span><span style="color:gray;">AND </span><span style="color:#434343;">@Length </span><span style="color:gray;">&gt; </span><span style="color:black;">0<br />
</span><span style="color:blue;">BEGIN<br />
SET </span><span style="color:#434343;">@HTMLText </span><span style="color:blue;">= </span><span style="color:magenta;">STUFF</span><span style="color:gray;">(</span><span style="color:#434343;">@HTMLText</span><span style="color:gray;">,</span><span style="color:#434343;">@Start</span><span style="color:gray;">,</span><span style="color:#434343;">@Length</span><span style="color:gray;">,</span><span style="color:red;">''</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@Start </span><span style="color:blue;">= CHARINDEX</span><span style="color:gray;">(</span><span style="color:red;">'&lt;'</span><span style="color:gray;">,</span><span style="color:#434343;">@HTMLText</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@End </span><span style="color:blue;">= CHARINDEX</span><span style="color:gray;">(</span><span style="color:red;">'&gt;'</span><span style="color:gray;">,</span><span style="color:#434343;">@HTMLText</span><span style="color:gray;">,</span><span style="color:blue;">CHARINDEX</span><span style="color:gray;">(</span><span style="color:red;">'&lt;'</span><span style="color:gray;">,</span><span style="color:#434343;">@HTMLText</span><span style="color:gray;">))<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@Length </span><span style="color:blue;">= </span><span style="color:gray;">(</span><span style="color:#434343;">@End </span><span style="color:gray;">- </span><span style="color:#434343;">@Start</span><span style="color:gray;">) + </span><span style="color:black;">1<br />
</span><span style="color:blue;">END<br />
RETURN </span><span style="color:magenta;">LTRIM</span><span style="color:gray;">(</span><span style="color:magenta;">RTRIM</span><span style="color:gray;">(</span><span style="color:#434343;">@HTMLText</span><span style="color:gray;">))<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span></code></p>
<p>Test above function like this :</p>
<p><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">dbo.udf_StripHTML</span><span style="color:gray;">(</span><span style="color:red;">'&lt;b&gt;UDF at SQLAuthority.com &lt;/b&gt;&lt;br&gt;&lt;br&gt;&lt;a href="http://www.SQLAuthority.com"&gt;SQLAuthority.com&lt;/a&gt;'</span><span style="color:gray;">)</span></code></p>
<p><strong>Result Set:</strong></p>
<p>UDF at SQLAuthority.com SQLAuthority.com</p>
<p>If you want to see this example in action click on Image. It will open large image.</p>
<p><a href="http://www.pinaldave.com/download/HTMLUDF_L.gif" target="_blank"><img src="http://www.pinaldave.com/download/HTMLUDF_S.gif" alt="" width="500" height="279" /></a></p>
<p>Reference : <strong>Pinal Dave (<a href="http://blog.SQLAuthority.com" target="_blank">http://blog.SQLAuthority.com</a>)</strong></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/204/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/204/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/204/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=204&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/06/16/sql-server-udf-user-defined-function-to-strip-html-parse-html-no-regular-expression/feed/</wfw:commentRss>
		<slash:comments>65</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/download/HTMLUDF_S.gif" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; 2005 Constraint on VARCHAR(MAX) Field To Limit It Certain Length</title>
		<link>http://blog.sqlauthority.com/2007/06/01/sql-server-2005-constraint-on-varcharmax-field-to-limit-it-certain-length/</link>
		<comments>http://blog.sqlauthority.com/2007/06/01/sql-server-2005-constraint-on-varcharmax-field-to-limit-it-certain-length/#comments</comments>
		<pubDate>Fri, 01 Jun 2007 14:00:16 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Constraint and Keys]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/01/sql-server-2005-constraint-on-varcharmax-field-to-limit-it-certain-length/</guid>
		<description><![CDATA[One of the Jr. DBA at in my Team Member asked me question the other day when he was replacing TEXT field with VARCHAR(MAX) : How can I limit the VARCHAR(MAX) field with maximum length of 12500 characters only. His Question was valid as our application was allowing 12500 characters. Traditionally thinking we only create [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=184&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">One of the Jr. DBA at in my Team Member asked me question the other day when he was replacing TEXT field with VARCHAR(MAX) : How can I limit the VARCHAR(MAX) field with maximum length of 12500 characters only. His Question was valid as our application was allowing 12500 characters.</p>
<p style="text-align:justify;">Traditionally thinking we only create the field as long as we need. SQL Server 2005 does support VARCHAR(MAX) but does not support VARCHAR(12500). If we try to create database field with VARCHAR(12500) it gives following error.</p>
<p style="text-align:justify;"><span style="color:#ff0000;">Server: Msg 131, Level 15, State 3, Line 1<br />
The size (12500) given to the type &#8216;varchar&#8217; exceeds the maximum allowed for any data type (8000).</span></p>
<p style="text-align:justify;">The solution we came up was to put constraint on the VARCHAR(MAX).  SQL SERVER 2005 supports VARCHAR(MAX) and Constraint.</p>
<p><code style="font-size:12px;"><span style="color:blue;">CREATE TABLE </span><span style="color:black;">[dbo].[MyTestTable] </span><span style="color:gray;">( </span><span style="color:black;">[VarChar12500] </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:blue;">MAX</span><span style="color:gray;">) )<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">ALTER TABLE </span><span style="color:black;">[dbo].[MyTestTable]<br />
</span><span style="color:blue;">ADD CONSTRAINT </span><span style="color:black;">[MaxLengthConstraint]<br />
</span><span style="color:blue;">CHECK </span><span style="color:gray;">(</span><span style="color:magenta;">DATALENGTH</span><span style="color:gray;">(</span><span style="color:black;">[VarChar12500]</span><span style="color:gray;">) &lt;= </span><span style="color:black;">12500</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span></code><br />
Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/184/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/184/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/184/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=184&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/06/01/sql-server-2005-constraint-on-varcharmax-field-to-limit-it-certain-length/feed/</wfw:commentRss>
		<slash:comments>45</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; 2005 Replace TEXT with VARCHAR(MAX) &#8211; Stop using TEXT, NTEXT, IMAGE Data Types</title>
		<link>http://blog.sqlauthority.com/2007/05/26/sql-server-2005-replace-text-with-varcharmax-stop-using-text-ntext-image-data-types/</link>
		<comments>http://blog.sqlauthority.com/2007/05/26/sql-server-2005-replace-text-with-varcharmax-stop-using-text-ntext-image-data-types/#comments</comments>
		<pubDate>Sat, 26 May 2007 14:00:50 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[SQL Datatype]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/26/sql-server-2005-replace-text-with-varcharmax-stop-using-text-ntext-image-data-types/</guid>
		<description><![CDATA[Yesterday, in Friday Afternoon team meeting. I was asked question by one of application developer &#8220;I am asked in new coding standards to use VARHCAR(MAX) instead of TEXT. Is VARCHAR(MAX) big enough to store TEXT field?&#8221; Well, I realize that I was not clear enough in my coding standard. It is extremely important for coding [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=214&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Yesterday, in Friday Afternoon team meeting. I was asked question by one of application developer</p>
<p style="text-align:justify;">&#8220;I am asked in new coding standards to use VARHCAR(MAX) instead of TEXT. Is VARCHAR(MAX) big enough to store TEXT field?&#8221;</p>
<p style="text-align:justify;">Well, I realize that I was not clear enough in my coding standard. It is extremely important for coding standards to be clear and have a enough explanation that developer have no doubt about them. I updated coding standards after the meeting.  The answer is</p>
<p style="text-align:justify;"><em>&#8220;Yes,  VARCHAR(MAX) is big enough to accommodate TEXT field. TEXT, NTEXT and IMAGE data types of SQL Server 2000 will be deprecated in future version of SQL Server, SQL Server 2005 provides backward compatibility to data types but it is recommanded to use new data types which are VARHCAR(MAX), NVARCHAR(MAX)  and VARBINARY(MAX).&#8221;</em></p>
<p style="text-align:justify;">There are more reasons to use VARHCAR(MAX) though this was verbal answer to technical question in our general meeting where the focus was &#8220;Web Application Architecture and SQL Server&#8221;.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/214/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/214/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/214/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=214&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/05/26/sql-server-2005-replace-text-with-varcharmax-stop-using-text-ntext-image-data-types/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; UDF &#8211; Function to Parse AlphaNumeric Characters from String</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-udf-function-to-parse-alphanumeric-characters-from-string/</link>
		<comments>http://blog.sqlauthority.com/2007/05/13/sql-server-udf-function-to-parse-alphanumeric-characters-from-string/#comments</comments>
		<pubDate>Sun, 13 May 2007 14:00:04 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-udf-function-to-parse-alphanumeric-characters-from-string/</guid>
		<description><![CDATA[Following function keeps only Alphanumeric characters in string and removes all the other character from the string. This is very handy function when working with Alphanumeric String only. I have used this many times. CREATE FUNCTION dbo.UDF_ParseAlphaChars ( @string VARCHAR(8000) ) RETURNS VARCHAR(8000) AS BEGIN DECLARE @IncorrectCharLoc SMALLINT SET @IncorrectCharLoc = PATINDEX('%[^0-9A-Za-z]%', @string) WHILE @IncorrectCharLoc [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=159&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Following function keeps only Alphanumeric characters in string and removes all the other character from the string. This is very handy function when working with Alphanumeric String only. I have used this many times.</p>
<p><code style="font-size:12px;"><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">dbo.UDF_ParseAlphaChars<br />
</span><span style="color:gray;">(<br />
</span><span style="color:#434343;">@string </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">8000</span><span style="color:gray;">)<br />
)<br />
</span><span style="color:blue;">RETURNS VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">8000</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
BEGIN<br />
DECLARE </span><span style="color:#434343;">@IncorrectCharLoc </span><span style="color:black;">SMALLINT<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@IncorrectCharLoc </span><span style="color:blue;">= </span><span style="color:magenta;">PATINDEX</span><span style="color:gray;">(</span><span style="color:red;">'%[^0-9A-Za-z]%'</span><span style="color:gray;">, </span><span style="color:#434343;">@string</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHILE </span><span style="color:#434343;">@IncorrectCharLoc </span><span style="color:gray;">&gt; </span><span style="color:black;">0<br />
</span><span style="color:blue;">BEGIN<br />
SET </span><span style="color:#434343;">@string </span><span style="color:blue;">= </span><span style="color:magenta;">STUFF</span><span style="color:gray;">(</span><span style="color:#434343;">@string</span><span style="color:gray;">, </span><span style="color:#434343;">@IncorrectCharLoc</span><span style="color:gray;">, </span><span style="color:black;">1</span><span style="color:gray;">, </span><span style="color:red;">''</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@IncorrectCharLoc </span><span style="color:blue;">= </span><span style="color:magenta;">PATINDEX</span><span style="color:gray;">(</span><span style="color:red;">'%[^0-9A-Za-z]%'</span><span style="color:gray;">, </span><span style="color:#434343;">@string</span><span style="color:gray;">)<br />
</span><span style="color:blue;">END<br />
SET </span><span style="color:#434343;">@string </span><span style="color:blue;">= </span><span style="color:#434343;">@string<br />
</span><span style="color:blue;">RETURN </span><span style="color:#434343;">@string<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span></code><br />
&#8212;-Test<br />
<code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">dbo.UDF_ParseAlphaChars</span><span style="color:gray;">(</span><span style="color:red;">'ABC”_I+{D[]}4|:e;””5,&lt;.F&gt;/?6'</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span></code><br />
<em><strong>Result Set :  ABCID4e5F6</strong></em>
</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/159/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/159/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/159/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=159&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/05/13/sql-server-udf-function-to-parse-alphanumeric-characters-from-string/feed/</wfw:commentRss>
		<slash:comments>78</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; User Defined Functions (UDF) to Reverse String &#8211; UDF_ReverseString</title>
		<link>http://blog.sqlauthority.com/2007/05/01/sql-server-user-defined-functions-udf-to-reverse-string-udf_reversestring/</link>
		<comments>http://blog.sqlauthority.com/2007/05/01/sql-server-user-defined-functions-udf-to-reverse-string-udf_reversestring/#comments</comments>
		<pubDate>Tue, 01 May 2007 14:00:59 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/01/sql-server-user-defined-functions-udf-to-reverse-string-udf_reversestring/</guid>
		<description><![CDATA[UDF_ReverseString UDF_ReverseString User Defined Functions returns the Reversed String starting from certain position. First parameters takes the string to be reversed. Second parameters takes the position from where the string starts reversing. Script of UDF_ReverseString function to return Reverse String. CREATE FUNCTION UDF_ReverseString ( @StringToReverse VARCHAR(8000), @StartPosition INT ) RETURNS VARCHAR(8000) AS BEGIN IF (@StartPosition [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=145&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;"><span style="font-weight:bold;">UDF_ReverseString</span><br />
UDF_ReverseString User Defined Functions returns the Reversed String starting from certain position.<br />
First parameters takes the string to be reversed.<br />
Second parameters takes the position from where the string starts reversing.</p>
<p style="text-align:justify;">Script of UDF_ReverseString function to return Reverse String.<br />
<code style="font-size:12px;"><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">UDF_ReverseString<br />
</span><span style="color:gray;">( </span><span style="color:#434343;">@StringToReverse </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">8000</span><span style="color:gray;">),<br />
</span><span style="color:#434343;">@StartPosition </span><span style="color:blue;">INT </span><span style="color:gray;">)<br />
</span><span style="color:blue;">RETURNS VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">8000</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
BEGIN<br />
IF </span><span style="color:gray;">(</span><span style="color:#434343;">@StartPosition </span><span style="color:gray;">&lt;= </span><span style="color:black;">0</span><span style="color:gray;">)<br />
OR (</span><span style="color:#434343;">@StartPosition </span><span style="color:gray;">&gt; </span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:#434343;">@StringToReverse</span><span style="color:gray;">))<br />
</span><span style="color:blue;">RETURN </span><span style="color:gray;">(</span><span style="color:magenta;">REVERSE</span><span style="color:gray;">(</span><span style="color:#434343;">@StringToReverse</span><span style="color:gray;">))<br />
</span><span style="color:blue;">RETURN </span><span style="color:gray;">(</span><span style="color:magenta;">STUFF </span><span style="color:gray;">(</span><span style="color:#434343;">@StringToReverse</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@StartPosition</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:#434343;">@StringToReverse</span><span style="color:gray;">) - </span><span style="color:#434343;">@StartPosition </span><span style="color:gray;">+ </span><span style="color:black;">1</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">REVERSE</span><span style="color:gray;">(</span><span style="color:magenta;">SUBSTRING </span><span style="color:gray;">(</span><span style="color:#434343;">@StringToReverse</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@StartPosition<br />
</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:#434343;">@StringToReverse</span><span style="color:gray;">) - </span><span style="color:#434343;">@StartPosition </span><span style="color:gray;">+ </span><span style="color:black;">1</span><span style="color:gray;">))))<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span></code><br />
Usage of above UDF_ReverseString:</p>
<p style="text-align:justify;"><span style="font-weight:bold;">Reversing the string from third position</span><br />
<code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">dbo.UDF_ReverseString</span><span style="color:gray;">(</span><span style="color:red;">'forward string'</span><span style="color:gray;">,</span><span style="color:black;">3</span><span style="color:gray;">)</span></code><br />
Results Set : <em>forgnirts draw</em></p>
<p style="text-align:justify;"><span style="font-weight:bold;">Reversing the entire string passing 0 as beginning character</span><br />
<code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">dbo.UDF_ReverseString</span><span style="color:gray;">(</span><span style="color:red;">'forward string'</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">)</span></code><br />
Results Set : <em>gnirts drawrof</em></p>
<p style="text-align:justify;"><span style="font-weight:bold;">Reversing the entire string passing negative number as beginning character</span><br />
<code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">dbo.UDF_ReverseString</span><span style="color:gray;">(</span><span style="color:red;">'forward string'</span><span style="color:gray;">,-</span><span style="color:black;">9</span><span style="color:gray;">)</span></code><br />
Results Set : <em>gnirts drawrof</em></p>
<p style="text-align:justify;"><span style="font-weight:bold;">Reversing the entire string passing larger number than string length as beginning character</span><br />
<code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">dbo.UDF_ReverseString</span><span style="color:gray;">(</span><span style="color:red;">'forward string'</span><span style="color:gray;">,</span><span style="color:black;">900</span><span style="color:gray;">)</span></code><br />
Results Set : gnirts drawrof</p>
<p style="text-align:justify;">SQL SERVER has REVERSE Function which is used in UDF above.<br />
If you have to reverse complete string. I would rather suggest use following script rather than using the UDF above. The purpose of the UDF is to reverse the string from certain positioned characters only.</p>
<p style="text-align:justify;"><span style="font-weight:bold;">Example for REVERSE function in SQL SERVER 2005 from BOL:</span><br />
<code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks</span><span style="color:gray;">;<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">FirstName</span><span style="color:gray;">, </span><span style="color:magenta;">REVERSE</span><span style="color:gray;">(</span><span style="color:black;">FirstName</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:magenta;">REVERSE<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Person.Contact<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">ContactID </span><span style="color:gray;">&lt; </span><span style="color:black;">5<br />
</span><span style="color:blue;">ORDER BY </span><span style="color:black;">FirstName</span><span style="color:gray;">;<br />
</span><span style="color:black;">GO<br />
</span></code></p>
<p style="text-align:justify;">FirstName      Reverse<br />
&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8211;<br />
Catherine      enirehtaC<br />
Gustavo        ovatsuG<br />
Humberto       otrebmuH<br />
Kim            miK<br />
(4 row(s) affected)</p>
<p>Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/145/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/145/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/145/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=145&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/05/01/sql-server-user-defined-functions-udf-to-reverse-string-udf_reversestring/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; UDF &#8211; User Defined Function to Extract Only Numbers From String</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/</link>
		<comments>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comments</comments>
		<pubDate>Wed, 11 Apr 2007 15:00:49 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/</guid>
		<description><![CDATA[Following SQL User Defined Function will extract/parse numbers from the string. CREATE FUNCTION ExtractInteger(@String VARCHAR(2000)) RETURNS VARCHAR(1000) AS BEGIN DECLARE @Count INT DECLARE @IntNumbers VARCHAR(1000) SET @Count = 0 SET @IntNumbers = '' WHILE @Count &#60;= LEN(@String) BEGIN IF SUBSTRING(@String,@Count,1) &#62;= '0' AND SUBSTRING(@String,@Count,1) &#60;= '9' BEGIN SET @IntNumbers = @IntNumbers + SUBSTRING(@String,@Count,1) END SET [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=90&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Following SQL User Defined Function will extract/parse numbers from the string.<br />
<code style="font-size:12px;"><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">ExtractInteger</span><span style="color:gray;">(</span><span style="color:#434343;">@String </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">2000</span><span style="color:gray;">))<br />
</span><span style="color:blue;">RETURNS VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">1000</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
BEGIN<br />
DECLARE </span><span style="color:#434343;">@Count </span><span style="color:blue;">INT<br />
DECLARE </span><span style="color:#434343;">@IntNumbers </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">1000</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@Count </span><span style="color:blue;">= </span><span style="color:black;">0<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@IntNumbers </span><span style="color:blue;">= </span><span style="color:red;">''</span></code></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">WHILE </span><span style="color:#434343;">@Count </span><span style="color:gray;">&lt;= </span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:#434343;">@String</span><span style="color:gray;">)<br />
</span><span style="color:blue;">BEGIN<br />
IF </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@String</span><span style="color:gray;">,</span><span style="color:#434343;">@Count</span><span style="color:gray;">,</span><span style="color:black;">1</span><span style="color:gray;">) &gt;= </span><span style="color:red;">'0'<br />
</span><span style="color:gray;">AND </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@String</span><span style="color:gray;">,</span><span style="color:#434343;">@Count</span><span style="color:gray;">,</span><span style="color:black;">1</span><span style="color:gray;">) &lt;= </span><span style="color:red;">'9'<br />
</span><span style="color:blue;">BEGIN<br />
SET </span><span style="color:#434343;">@IntNumbers </span><span style="color:blue;">= </span><span style="color:#434343;">@IntNumbers </span><span style="color:gray;">+ </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@String</span><span style="color:gray;">,</span><span style="color:#434343;">@Count</span><span style="color:gray;">,</span><span style="color:black;">1</span><span style="color:gray;">)<br />
</span><span style="color:blue;">END<br />
SET </span><span style="color:#434343;">@Count </span><span style="color:blue;">= </span><span style="color:#434343;">@Count </span><span style="color:gray;">+ </span><span style="color:black;">1<br />
</span><span style="color:blue;">END<br />
</span></code></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">RETURN </span><span style="color:#434343;">@IntNumbers<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span></code><br />
Run following script in query analyzer.<br />
<code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">dbo.ExtractInteger</span><span style="color:gray;">(</span><span style="color:red;">'My 3rd Phone Number is 323-111-CALL'</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span></code><br />
It will return following values.<br />
<code style="font-size:12px;"><span style="color:black;">3323111</span></code></p>
<p>Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/90/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/90/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/90/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=90&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Creating Comma Separate List From Table</title>
		<link>http://blog.sqlauthority.com/2007/02/20/deprecate-dec-2007-creating-comma-separate-list-from-table/</link>
		<comments>http://blog.sqlauthority.com/2007/02/20/deprecate-dec-2007-creating-comma-separate-list-from-table/#comments</comments>
		<pubDate>Tue, 20 Feb 2007 15:00:13 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/20/creating-comma-separate-list-from-table/</guid>
		<description><![CDATA[Update : (5/5/2007) I have updated the script to support SQL SERVER 2005. Visit :SQL SERVER &#8211; Creating Comma Separate Values List from Table &#8211; UDF &#8211; SP Reference : Pinal Dave (http://blog.SQLAuthority.com)<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=21&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;"><strong><em>Update : (5/5/2007)<br />
</em></strong><em><strong>I have updated the script to support SQL SERVER 2005. </strong></em><br />
Visit :<a href="http://blog.sqlauthority.com/2007/05/06/sql-server-creating-comma-separate-values-list-from-table-udf-sp/"><strong>SQL SERVER &#8211; Creating Comma Separate Values List from Table &#8211; UDF &#8211; SP</strong></a></p>
<p>Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=21&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/02/20/deprecate-dec-2007-creating-comma-separate-list-from-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Function to Convert List to Table</title>
		<link>http://blog.sqlauthority.com/2007/02/10/sql-server-function-to-convert-list-to-table/</link>
		<comments>http://blog.sqlauthority.com/2007/02/10/sql-server-function-to-convert-list-to-table/#comments</comments>
		<pubDate>Sat, 10 Feb 2007 07:00:22 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL String]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=20</guid>
		<description><![CDATA[Update : (5/5/2007) I have updated the UDF to support SQL SERVER 2005. Visit :SQL SERVER &#8211; UDF &#8211; Function to Convert List to Table Reference : Pinal Dave (http://blog.SQLAuthority.com)<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=20&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;"><strong><em>Update : (5/5/2007)</em></strong><br />
<em><strong>I have updated the UDF to support SQL SERVER 2005. </strong></em><br />
Visit :<a href="http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/"><strong>SQL SERVER &#8211; UDF &#8211; Function to Convert List to Table</strong></a></p>
<p>Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/20/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/20/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=20&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/02/10/sql-server-function-to-convert-list-to-table/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
	</channel>
</rss>
