Anith Sen
3/28/2007 10:45:00 PM
>> It doesn't seem that any of the listed methods are bullet proof for
>> removing all non-numeric data from a varchar telephone number.
Well, it is scrubbing & SQL is not the best choice to begin with. So we are
left with whatever is available at our disposal. The variation of the
approach you described is already among the listed methods.
CREATE FUNCTION dbo.udf ( @s VARCHAR(20) )
RETURNS VARCHAR(20) AS BEGIN
WHILE PATINDEX( '%[^0-9]%', @s ) > 0
SET @s = REPLACE( @s, SUBSTRING( @s,
PATINDEX( '%[^0-9]%', @s ), 1 ), '' )
RETURN @s END
GO
SELECT dbo.udf(' 2#^7)213 454-33' ) ;
--
Anith