﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss content posted by Scott Williams / Article Discussions / Article Discussions by Author  / Allow Only Numbers / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 25 May 2013 11:07:41 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Allow Only Numbers</title><link>http://www.sqlservercentral.com/Forums/Topic509558-439-1.aspx</link><description>Hi Scott...You have some minor errors you need to fix... (found in 2k, and 2k5)[color="RED"]Msg 102, Level 15, State 1, Procedure fnc_AllowNumbersOnly, Line 8Incorrect syntax near ' '.Msg 102, Level 15, State 1, Procedure fnc_AllowNumbersOnly, Line 9Incorrect syntax near ' '.[/color]The cause of the errors is 4 hidden characters just before the DECLARE and the WHILE.  Past the code into MS Word to see them.Also, consider getting rid of the @lenPhone and @phoneStr variables since they're declared but not used anywhere.If I may suggest, consider not using the WHILE loop at all... consider the Tally table which makes things run more than twice as fast when a fair number non-digit characters are present and still about 20% faster than when they are not....  Yeah, I know... I could use LIKE... but the OR, in this case, shaves an extra second off a 10,000 row run when there's more than just a couple of non-numeric digits...[code] CREATE FUNCTION dbo.fnDigitsOnly        (@String NVARCHAR(4000))RETURNS NVARCHAR(4000)     AS  BEGIN         SELECT @String = STUFF(@String,N,1,'')           FROM dbo.Tally          WHERE N &amp;lt;= LEN(@String)            AND (SUBSTRING(@String,N,1) &amp;lt; '0'                 OR                  SUBSTRING(@String,N,1) &amp;gt; '9')          ORDER BY N DESC RETURN @String    END[/code]Tally table may be found here...[url]http://www.sqlservercentral.com/articles/TSQL/62867/[/url]</description><pubDate>Sun, 01 Jun 2008 21:48:03 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>Allow Only Numbers</title><link>http://www.sqlservercentral.com/Forums/Topic509558-439-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/Numbers+Only/63174/"&gt;Allow Only Numbers&lt;/A&gt;[/B]</description><pubDate>Sun, 01 Jun 2008 03:09:35 GMT</pubDate><dc:creator>Scott Williams</dc:creator></item></channel></rss>