View Single Post
  #7 (permalink)  
Old February 28th, 2006, 01:57 PM
Mickel Mickel is offline
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's a corrected version of the PhoneStrip function:

--Function will strip away any non-numeric characters in a free text
--phone number field

CREATE FUNCTION PhoneStrip (@expression varchar(20))
RETURNS varchar(20)
AS
BEGIN
    DECLARE @index int
    DECLARE @return varchar(20)

   Set @index = 1
   Set @return=''

    WHILE @index < LEN(@expression)+1
    BEGIN
        IF SUBSTRING(@expression, @index, 1) BETWEEN '0' AND '9'
          Set @return = @return + SUBSTRING(@expression, @index, 1)
        Set @index = @index + 1
    END
    RETURN @return
END


Reply With Quote