DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to filter non-digits with a scalar function?

Execute the following SQL Server Script in SSMS Query Editor create a non-digit filter function:

USE AdventureWorks2008;

GO

 

CREATE FUNCTION fnFilterNonDigit

               (@Input VARCHAR(256))

RETURNS VARCHAR(256)

AS

  BEGIN

    IF PATINDEX('%[^0-9]%',@Input) > 0

      WHILE PATINDEX('%[^0-9]%',@Input) > 0

        SET @Input = Stuff(@Input,PATINDEX('%[^0-9]%',@Input),1,'')

    

    RETURN @Input

  END

 

GO

 

SELECT dbo.fnFilterNonDigit('aaa123bbb456c7890ddd0124 56')

-- 1234567890012456

 

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE