CREATE FUNCTION [dbo].[REMOVE_NONINTEGERS](@TEXT VARCHAR(MAX))
RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @Reset BIT;
DECLARE @Ret VARCHAR(8000);
DECLARE @i INT;
DECLARE @c CHAR(1);
DECLARE @CharLength INT
DECLARE @CHARSTART INT
DECLARE @RESULT VARCHAR(MAX)
SET @I = 1
SET @CHARSTART = 0
WHILE (@i <= LEN(@Text))
BEGIN
SET @CHARSTART = @CHARSTART + 1
SET @RET = SUBSTRING(@TEXT,@CHARSTART,1)
IF(@RET NOT in('0','1','2','3','4','5','6','7','8','9'))
BEGIN
SET @RET = ISNULL(@RET,'')
SET @I = @I + 1
END
ELSE
BEGIN
SET @RESULT = ISNULL(@RESULT,'') + @RET
SET @I = @I + 1
END
END
RETURN @RESULT
END
SELECT [dbo].[REMOVE_NONINTEGERS]('100000187^Visit-NCH')