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 VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
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
SQL 2016 DESIGN & PROGRAMMING
 
 
 
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