<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; UDF &#8211; User Defined Function to Extract Only Numbers From String</title>
	<atom:link href="http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Fri, 10 Feb 2012 05:05:02 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Q:</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-164424</link>
		<dc:creator><![CDATA[Q:]]></dc:creator>
		<pubDate>Thu, 01 Sep 2011 20:38:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-164424</guid>
		<description><![CDATA[Hi Pinal ,

Should the LEN(@String) in the query above be passed to avariable and then compare the while loop to a variable. Is there a performance difference between the two menthods.]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal ,</p>
<p>Should the LEN(@String) in the query above be passed to avariable and then compare the while loop to a variable. Is there a performance difference between the two menthods.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mei Pogorelc</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-156345</link>
		<dc:creator><![CDATA[Mei Pogorelc]]></dc:creator>
		<pubDate>Fri, 12 Aug 2011 01:49:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-156345</guid>
		<description><![CDATA[I really am delighting in your blog I observed it via yahoo yesterday.]]></description>
		<content:encoded><![CDATA[<p>I really am delighting in your blog I observed it via yahoo yesterday.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-116031</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Fri, 04 Feb 2011 11:46:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-116031</guid>
		<description><![CDATA[Select top * from table
order by col]]></description>
		<content:encoded><![CDATA[<p>Select top * from table<br />
order by col</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: prashant</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-115489</link>
		<dc:creator><![CDATA[prashant]]></dc:creator>
		<pubDate>Tue, 01 Feb 2011 07:09:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-115489</guid>
		<description><![CDATA[Hi ,
I want to create one function which shold return result of 
select query which is just column with top 10 values.
Bit of code will help.
so basically fuction will return those top 10 vales of one restult columnt. What type of variable shold i take for returnig those 10 values ?]]></description>
		<content:encoded><![CDATA[<p>Hi ,<br />
I want to create one function which shold return result of<br />
select query which is just column with top 10 values.<br />
Bit of code will help.<br />
so basically fuction will return those top 10 vales of one restult columnt. What type of variable shold i take for returnig those 10 values ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Agnes</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-91462</link>
		<dc:creator><![CDATA[Agnes]]></dc:creator>
		<pubDate>Wed, 06 Oct 2010 11:09:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-91462</guid>
		<description><![CDATA[There is a point in yout SQL coding standard that
•	Always put the DECLARE statement at the starting of the code in the stored procedure. This will make the query optimizer to reuse query plans.

What does it mean &quot;the query optimizer to reuse query plans.&quot;?

And one more doubt which is the best practice of following the declare statement.
Is it Declare @variable1 int,@variable2 varchar(10)

or Declare @variable1 int
   Declare @variable2 varchar(10)]]></description>
		<content:encoded><![CDATA[<p>There is a point in yout SQL coding standard that<br />
•	Always put the DECLARE statement at the starting of the code in the stored procedure. This will make the query optimizer to reuse query plans.</p>
<p>What does it mean &#8220;the query optimizer to reuse query plans.&#8221;?</p>
<p>And one more doubt which is the best practice of following the declare statement.<br />
Is it Declare @variable1 int,@variable2 varchar(10)</p>
<p>or Declare @variable1 int<br />
   Declare @variable2 varchar(10)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: john holloway</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-87113</link>
		<dc:creator><![CDATA[john holloway]]></dc:creator>
		<pubDate>Wed, 08 Sep 2010 18:29:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-87113</guid>
		<description><![CDATA[I would like a series of data that looks like this
D1
D10
D2
D1AW

To sort like this
D1
D1AW
D2
D10

I would very much appreciate any help with this sort.]]></description>
		<content:encoded><![CDATA[<p>I would like a series of data that looks like this<br />
D1<br />
D10<br />
D2<br />
D1AW</p>
<p>To sort like this<br />
D1<br />
D1AW<br />
D2<br />
D10</p>
<p>I would very much appreciate any help with this sort.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alex</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-80539</link>
		<dc:creator><![CDATA[alex]]></dc:creator>
		<pubDate>Fri, 16 Jul 2010 20:51:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-80539</guid>
		<description><![CDATA[disregard me first question, i figured it out:

SELECT cast(dbo.ExtractNumbers(pub)as int) as newcol, pub from test_table order by newcol desc]]></description>
		<content:encoded><![CDATA[<p>disregard me first question, i figured it out:</p>
<p>SELECT cast(dbo.ExtractNumbers(pub)as int) as newcol, pub from test_table order by newcol desc</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alex</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-80536</link>
		<dc:creator><![CDATA[alex]]></dc:creator>
		<pubDate>Fri, 16 Jul 2010 20:49:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-80536</guid>
		<description><![CDATA[also, how can i modify this function to check if the first integer of the output is a &quot;1&quot;, if so, delete it.]]></description>
		<content:encoded><![CDATA[<p>also, how can i modify this function to check if the first integer of the output is a &#8220;1&#8243;, if so, delete it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alex</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-80533</link>
		<dc:creator><![CDATA[alex]]></dc:creator>
		<pubDate>Fri, 16 Jul 2010 20:03:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-80533</guid>
		<description><![CDATA[I&#039;m using your &quot;integer extractor&quot; function to output a temporary field which I’ll use to sort a list. only problem is, the output is varchar and therefore the numbers are sorting  correctly. how can i convert the output to an INT datatype. 

my query:

SELECT dbo.ExtractNumbers(pub) as newcol, title from test_table
 order by newcol desc]]></description>
		<content:encoded><![CDATA[<p>I&#8217;m using your &#8220;integer extractor&#8221; function to output a temporary field which I’ll use to sort a list. only problem is, the output is varchar and therefore the numbers are sorting  correctly. how can i convert the output to an INT datatype. </p>
<p>my query:</p>
<p>SELECT dbo.ExtractNumbers(pub) as newcol, title from test_table<br />
 order by newcol desc</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-63787</link>
		<dc:creator><![CDATA[Madhivanan]]></dc:creator>
		<pubDate>Fri, 26 Mar 2010 08:59:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-63787</guid>
		<description><![CDATA[Other methods

declare @s varchar(100)
set @s=&#039;50.00 on 04/06/2009&#039;
select substring ( @s, 1, charindex (&#039; &#039;, @s)-1)
select substring (@s , 1, patindex (&#039;%[0] %&#039;, @s))

Also refer this post
http://beyondrelational.com/blogs/madhivanan/archive/2009/11/18/parsing-a-string.aspx]]></description>
		<content:encoded><![CDATA[<p>Other methods</p>
<p>declare @s varchar(100)<br />
set @s=&#39;50.00 on 04/06/2009&#39;<br />
select substring ( @s, 1, charindex (&#39; &#39;, @s)-1)<br />
select substring (@s , 1, patindex (&#39;%[0] %&#39;, @s))</p>
<p>Also refer this post<br />
<a href="http://beyondrelational.com/blogs/madhivanan/archive/2009/11/18/parsing-a-string.aspx" rel="nofollow">http://beyondrelational.com/blogs/madhivanan/archive/2009/11/18/parsing-a-string.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-62504</link>
		<dc:creator><![CDATA[Madhivanan]]></dc:creator>
		<pubDate>Tue, 09 Mar 2010 10:23:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-62504</guid>
		<description><![CDATA[declare @s varchar(1000)
set @s=&#039;person A at 2006 345 15:24 See attachment from Ron Holden person B at 2006 361 16:20 Refer to AR 113831.&#039;
select substring(@s,patindex(&#039;%[0-9]%&#039;,@s),patindex(&#039;%:%&#039;,@s)+2-patindex(&#039;%[0-9]%&#039;,@s)+1)]]></description>
		<content:encoded><![CDATA[<p>declare @s varchar(1000)<br />
set @s=&#8217;person A at 2006 345 15:24 See attachment from Ron Holden person B at 2006 361 16:20 Refer to AR 113831.&#8217;<br />
select substring(@s,patindex(&#8216;%[0-9]%&#8217;,@s),patindex(&#8216;%:%&#8217;,@s)+2-patindex(&#8216;%[0-9]%&#8217;,@s)+1)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-62398</link>
		<dc:creator><![CDATA[Madhivanan]]></dc:creator>
		<pubDate>Mon, 08 Mar 2010 10:36:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-62398</guid>
		<description><![CDATA[declare @s varchar(100)
set @s=&#039;AP1BC_77&#039;
select substring(@s,charindex(&#039;_&#039;,@s)+1,len(@s))]]></description>
		<content:encoded><![CDATA[<p>declare @s varchar(100)<br />
set @s=&#8217;AP1BC_77&#8242;<br />
select substring(@s,charindex(&#8216;_&#8217;,@s)+1,len(@s))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-62396</link>
		<dc:creator><![CDATA[Madhivanan]]></dc:creator>
		<pubDate>Mon, 08 Mar 2010 10:34:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-62396</guid>
		<description><![CDATA[You can use many methods

Refer this

http://beyondrelational.com/blogs/madhivanan/archive/2007/10/10/generating-random-numbers-part-ii.aspx]]></description>
		<content:encoded><![CDATA[<p>You can use many methods</p>
<p>Refer this</p>
<p><a href="http://beyondrelational.com/blogs/madhivanan/archive/2007/10/10/generating-random-numbers-part-ii.aspx" rel="nofollow">http://beyondrelational.com/blogs/madhivanan/archive/2007/10/10/generating-random-numbers-part-ii.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-62393</link>
		<dc:creator><![CDATA[Madhivanan]]></dc:creator>
		<pubDate>Mon, 08 Mar 2010 10:31:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-62393</guid>
		<description><![CDATA[Where col like &#039;%[0-9]%&#039; and col like &#039;%[a-zA-Z]%&#039;]]></description>
		<content:encoded><![CDATA[<p>Where col like &#8216;%[0-9]%&#8217; and col like &#8216;%[a-zA-Z]%&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-62391</link>
		<dc:creator><![CDATA[Madhivanan]]></dc:creator>
		<pubDate>Mon, 08 Mar 2010 10:27:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-62391</guid>
		<description><![CDATA[Refer this and change [0-9] to [a-z]

http://beyondrelational.com/blogs/madhivanan/archive/2007/12/18/extract-only-numbers-from-a-string.aspx]]></description>
		<content:encoded><![CDATA[<p>Refer this and change [0-9] to [a-z]</p>
<p><a href="http://beyondrelational.com/blogs/madhivanan/archive/2007/12/18/extract-only-numbers-from-a-string.aspx" rel="nofollow">http://beyondrelational.com/blogs/madhivanan/archive/2007/12/18/extract-only-numbers-from-a-string.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-58958</link>
		<dc:creator><![CDATA[Chris]]></dc:creator>
		<pubDate>Wed, 23 Dec 2009 19:52:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-58958</guid>
		<description><![CDATA[Heres an alternative method that seems to have better performance. The method described above took about 30 seconds over my test data whereas the method below takes about 11 seconds over the same data.


create function [dbo].[ExtractNumbers](@Numbers nvarchar(2000))
returns nvarchar(2000)
as
BEGIN

declare @NonNumericIndex int
set @NonNumericIndex = PATINDEX(&#039;%[^0-9]%&#039;,@Numbers)

WHILE @NonNumericIndex &gt; 0
begin
	SET @Numbers = REPLACE(@Numbers,SUBSTRING(@Numbers,@NonNumericIndex,1),&#039;&#039;)
	set @NonNumericIndex = PATINDEX(&#039;%[^0-9]%&#039;,@Numbers)
end

return @Numbers

END]]></description>
		<content:encoded><![CDATA[<p>Heres an alternative method that seems to have better performance. The method described above took about 30 seconds over my test data whereas the method below takes about 11 seconds over the same data.</p>
<p>create function [dbo].[ExtractNumbers](@Numbers nvarchar(2000))<br />
returns nvarchar(2000)<br />
as<br />
BEGIN</p>
<p>declare @NonNumericIndex int<br />
set @NonNumericIndex = PATINDEX(&#8216;%[^0-9]%&#8217;,@Numbers)</p>
<p>WHILE @NonNumericIndex &gt; 0<br />
begin<br />
	SET @Numbers = REPLACE(@Numbers,SUBSTRING(@Numbers,@NonNumericIndex,1),&#8221;)<br />
	set @NonNumericIndex = PATINDEX(&#8216;%[^0-9]%&#8217;,@Numbers)<br />
end</p>
<p>return @Numbers</p>
<p>END</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dorababu</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-58342</link>
		<dc:creator><![CDATA[Dorababu]]></dc:creator>
		<pubDate>Wed, 09 Dec 2009 04:47:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-58342</guid>
		<description><![CDATA[Hi all i need a small help,
                                          I am having my string like this AP1BC_77.. I would like to display only 77 like that if we have any sort of string but i would like to display only the numeric appended to the end of the characters. Can any one help me please..]]></description>
		<content:encoded><![CDATA[<p>Hi all i need a small help,<br />
                                          I am having my string like this AP1BC_77.. I would like to display only 77 like that if we have any sort of string but i would like to display only the numeric appended to the end of the characters. Can any one help me please..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stefan</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-56114</link>
		<dc:creator><![CDATA[Stefan]]></dc:creator>
		<pubDate>Thu, 24 Sep 2009 07:25:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-56114</guid>
		<description><![CDATA[Thanks a lot. Very helpful.]]></description>
		<content:encoded><![CDATA[<p>Thanks a lot. Very helpful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: adam</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-54275</link>
		<dc:creator><![CDATA[adam]]></dc:creator>
		<pubDate>Thu, 30 Jul 2009 16:35:47 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-54275</guid>
		<description><![CDATA[how can i get all numeric values as a table ?

i mean, the result should be in a table like that..

Number
3
323
111

not scalar varchar value...

Thanks]]></description>
		<content:encoded><![CDATA[<p>how can i get all numeric values as a table ?</p>
<p>i mean, the result should be in a table like that..</p>
<p>Number<br />
3<br />
323<br />
111</p>
<p>not scalar varchar value&#8230;</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-52857</link>
		<dc:creator><![CDATA[pinaldave]]></dc:creator>
		<pubDate>Tue, 09 Jun 2009 03:39:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-52857</guid>
		<description><![CDATA[This comment is sent to me in email by our SQL Expert Imran Mohammed.

Reply to Asif, 

@Asif

CREATE FUNCTION [dbo].[UFN_Eliminate_Alphabet] (@string varchar(max))
RETURNS int 
AS
BEGIN 
	DECLARE @result varchar(50)
	DECLARE @position int
		SET @position = 1
		SET @result = &#039;&#039;

	WHILE @position &lt;= DATALENGTH(@string)
	   BEGIN
			SELECT @result = @result +	case	when (ASCII(SUBSTRING(@string, @position, 1))) between 48 and 57 then SUBSTRING(@string, @position, 1)
												else &#039;&#039;
										end 
			SET @position = @position + 1
	   END
		RETURN ( select convert ( int, @result))
END 
GO 
-- Sample to Execute 
select [dbo].[UFN_Eliminate_Alphabet](&#039;abc64h5n5u&#039;)
GO
CREATE FUNCTION [dbo].[UFN_Eliminate_Numbers] (@string varchar(max))
RETURNS varchar  (max)
AS
BEGIN
	DECLARE @result varchar(50)
	DECLARE @position int
		SET @position = 1
		Set @result = &#039;&#039;
	WHILE @position &lt;= DATALENGTH(@string)
		BEGIN
			SELECT @result = @result +	case	when	ASCII(SUBSTRING(@string, @position, 1)) between 97 and 122 then SUBSTRING(@string, @position, 1)
												when	ASCII(SUBSTRING(@string, @position, 1)) between 65 and 90 then SUBSTRING(@string, @position, 1)
												else	&#039;&#039;
										end 
			SET @position = @position + 1
		END
	RETURN	( select @result As ID 	)
END
GO 
-- Sample to Execute 
select [dbo].[UFN_Eliminate_Numbers](&#039;abc64h5n5u&#039;)
GO]]></description>
		<content:encoded><![CDATA[<p>This comment is sent to me in email by our SQL Expert Imran Mohammed.</p>
<p>Reply to Asif, </p>
<p>@Asif</p>
<p>CREATE FUNCTION [dbo].[UFN_Eliminate_Alphabet] (@string varchar(max))<br />
RETURNS int<br />
AS<br />
BEGIN<br />
	DECLARE @result varchar(50)<br />
	DECLARE @position int<br />
		SET @position = 1<br />
		SET @result = &#8221;</p>
<p>	WHILE @position &lt;= DATALENGTH(@string)<br />
	   BEGIN<br />
			SELECT @result = @result +	case	when (ASCII(SUBSTRING(@string, @position, 1))) between 48 and 57 then SUBSTRING(@string, @position, 1)<br />
												else &#039;&#039;<br />
										end<br />
			SET @position = @position + 1<br />
	   END<br />
		RETURN ( select convert ( int, @result))<br />
END<br />
GO<br />
&#8211; Sample to Execute<br />
select [dbo].[UFN_Eliminate_Alphabet](&#039;abc64h5n5u&#039;)<br />
GO<br />
CREATE FUNCTION [dbo].[UFN_Eliminate_Numbers] (@string varchar(max))<br />
RETURNS varchar  (max)<br />
AS<br />
BEGIN<br />
	DECLARE @result varchar(50)<br />
	DECLARE @position int<br />
		SET @position = 1<br />
		Set @result = &#039;&#039;<br />
	WHILE @position &lt;= DATALENGTH(@string)<br />
		BEGIN<br />
			SELECT @result = @result +	case	when	ASCII(SUBSTRING(@string, @position, 1)) between 97 and 122 then SUBSTRING(@string, @position, 1)<br />
												when	ASCII(SUBSTRING(@string, @position, 1)) between 65 and 90 then SUBSTRING(@string, @position, 1)<br />
												else	&#039;&#039;<br />
										end<br />
			SET @position = @position + 1<br />
		END<br />
	RETURN	( select @result As ID 	)<br />
END<br />
GO<br />
&#8211; Sample to Execute<br />
select [dbo].[UFN_Eliminate_Numbers](&#039;abc64h5n5u&#039;)<br />
GO</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-52856</link>
		<dc:creator><![CDATA[Imran Mohammed]]></dc:creator>
		<pubDate>Tue, 09 Jun 2009 03:34:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-52856</guid>
		<description><![CDATA[Reply to Asif, 

First function 

CREATE FUNCTION [dbo].[UFN_Eliminate_Alphabet] (@string varchar(max))
RETURNS int 
AS
BEGIN 
	DECLARE @result varchar(50)
	DECLARE @position int
		SET @position = 1
		SET @result = &#039;&#039;

	WHILE @position &lt;= DATALENGTH(@string)
	   BEGIN
			SELECT @result = @result +	case	when (ASCII(SUBSTRING(@string, @position, 1))) between 48 and 57 then SUBSTRING(@string, @position, 1)
												else &#039;&#039;
										end 
			SET @position = @position + 1
	   END
		RETURN ( select convert ( int, @result))
END 
GO 
-- Sample to Execute 
select [dbo].[UFN_Eliminate_Alphabet](&#039;abc64h5n5u&#039;)

~IM]]></description>
		<content:encoded><![CDATA[<p>Reply to Asif, </p>
<p>First function </p>
<p>CREATE FUNCTION [dbo].[UFN_Eliminate_Alphabet] (@string varchar(max))<br />
RETURNS int<br />
AS<br />
BEGIN<br />
	DECLARE @result varchar(50)<br />
	DECLARE @position int<br />
		SET @position = 1<br />
		SET @result = &#8221;</p>
<p>	WHILE @position &lt;= DATALENGTH(@string)<br />
	   BEGIN<br />
			SELECT @result = @result +	case	when (ASCII(SUBSTRING(@string, @position, 1))) between 48 and 57 then SUBSTRING(@string, @position, 1)<br />
												else &#039;&#039;<br />
										end<br />
			SET @position = @position + 1<br />
	   END<br />
		RETURN ( select convert ( int, @result))<br />
END<br />
GO<br />
&#8211; Sample to Execute<br />
select [dbo].[UFN_Eliminate_Alphabet](&#039;abc64h5n5u&#039;)</p>
<p>~IM</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-52855</link>
		<dc:creator><![CDATA[Imran Mohammed]]></dc:creator>
		<pubDate>Tue, 09 Jun 2009 03:33:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-52855</guid>
		<description><![CDATA[Reply to Asif, 

@Asif

CREATE FUNCTION [dbo].[UFN_Eliminate_Alphabet] (@string varchar(max))
RETURNS int 
AS
BEGIN 
	DECLARE @result varchar(50)
	DECLARE @position int
		SET @position = 1
		SET @result = &#039;&#039;

	WHILE @position &lt;= DATALENGTH(@string)
	   BEGIN
			SELECT @result = @result +	case	when (ASCII(SUBSTRING(@string, @position, 1))) between 48 and 57 then SUBSTRING(@string, @position, 1)
												else &#039;&#039;
										end 
			SET @position = @position + 1
	   END
		RETURN ( select convert ( int, @result))
END 
GO 
-- Sample to Execute 
select [dbo].[UFN_Eliminate_Alphabet](&#039;abc64h5n5u&#039;)
GO
CREATE FUNCTION [dbo].[UFN_Eliminate_Numbers] (@string varchar(max))
RETURNS varchar  (max)
AS
BEGIN
	DECLARE @result varchar(50)
	DECLARE @position int
		SET @position = 1
		Set @result = &#039;&#039;
	WHILE @position &lt;= DATALENGTH(@string)
		BEGIN
			SELECT @result = @result +	case	when	ASCII(SUBSTRING(@string, @position, 1)) between 97 and 122 then SUBSTRING(@string, @position, 1)
												when	ASCII(SUBSTRING(@string, @position, 1)) between 65 and 90 then SUBSTRING(@string, @position, 1)
												else	&#039;&#039;
										end 
			SET @position = @position + 1
		END
	RETURN	( select @result As ID 	)
END
GO 
-- Sample to Execute 
select [dbo].[UFN_Eliminate_Numbers](&#039;abc64h5n5u&#039;)
GO]]></description>
		<content:encoded><![CDATA[<p>Reply to Asif, </p>
<p>@Asif</p>
<p>CREATE FUNCTION [dbo].[UFN_Eliminate_Alphabet] (@string varchar(max))<br />
RETURNS int<br />
AS<br />
BEGIN<br />
	DECLARE @result varchar(50)<br />
	DECLARE @position int<br />
		SET @position = 1<br />
		SET @result = &#8221;</p>
<p>	WHILE @position &lt;= DATALENGTH(@string)<br />
	   BEGIN<br />
			SELECT @result = @result +	case	when (ASCII(SUBSTRING(@string, @position, 1))) between 48 and 57 then SUBSTRING(@string, @position, 1)<br />
												else &#039;&#039;<br />
										end<br />
			SET @position = @position + 1<br />
	   END<br />
		RETURN ( select convert ( int, @result))<br />
END<br />
GO<br />
&#8211; Sample to Execute<br />
select [dbo].[UFN_Eliminate_Alphabet](&#039;abc64h5n5u&#039;)<br />
GO<br />
CREATE FUNCTION [dbo].[UFN_Eliminate_Numbers] (@string varchar(max))<br />
RETURNS varchar  (max)<br />
AS<br />
BEGIN<br />
	DECLARE @result varchar(50)<br />
	DECLARE @position int<br />
		SET @position = 1<br />
		Set @result = &#039;&#039;<br />
	WHILE @position &lt;= DATALENGTH(@string)<br />
		BEGIN<br />
			SELECT @result = @result +	case	when	ASCII(SUBSTRING(@string, @position, 1)) between 97 and 122 then SUBSTRING(@string, @position, 1)<br />
												when	ASCII(SUBSTRING(@string, @position, 1)) between 65 and 90 then SUBSTRING(@string, @position, 1)<br />
												else	&#039;&#039;<br />
										end<br />
			SET @position = @position + 1<br />
		END<br />
	RETURN	( select @result As ID 	)<br />
END<br />
GO<br />
&#8211; Sample to Execute<br />
select [dbo].[UFN_Eliminate_Numbers](&#039;abc64h5n5u&#039;)<br />
GO</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Tkatch</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-52838</link>
		<dc:creator><![CDATA[Brian Tkatch]]></dc:creator>
		<pubDate>Mon, 08 Jun 2009 17:00:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-52838</guid>
		<description><![CDATA[@asif

Please provide sample output.]]></description>
		<content:encoded><![CDATA[<p>@asif</p>
<p>Please provide sample output.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: asif</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-52835</link>
		<dc:creator><![CDATA[asif]]></dc:creator>
		<pubDate>Mon, 08 Jun 2009 16:01:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-52835</guid>
		<description><![CDATA[plz help me i have a table which contained alpha numeric values like this 1235abcd7412 nofixed length and other row contained abcvd52a1a2 

account
1235abcd7412
abcfd52a1a2
ghti5214ve3
asif214bv2


nofixed length account column plz show me easy query 

thanks 
asif]]></description>
		<content:encoded><![CDATA[<p>plz help me i have a table which contained alpha numeric values like this 1235abcd7412 nofixed length and other row contained abcvd52a1a2 </p>
<p>account<br />
1235abcd7412<br />
abcfd52a1a2<br />
ghti5214ve3<br />
asif214bv2</p>
<p>nofixed length account column plz show me easy query </p>
<p>thanks<br />
asif</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: asif</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-udf-user-defined-function-to-extract-only-numbers-from-string/#comment-52776</link>
		<dc:creator><![CDATA[asif]]></dc:creator>
		<pubDate>Fri, 05 Jun 2009 16:57:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-user-defined-function-to-extract-only-numbers-from-string/#comment-52776</guid>
		<description><![CDATA[I want to isolate alphanumeric values like
column a values 456abc123def
I want to sepateit]]></description>
		<content:encoded><![CDATA[<p>I want to isolate alphanumeric values like<br />
column a values 456abc123def<br />
I want to sepateit</p>
]]></content:encoded>
	</item>
</channel>
</rss>

