IF OBJECT_ID('F_NUMEROS') IS NOT NULL
BEGIN
	DROP FUNCTION F_NUMEROS;
END; 
GO
CREATE FUNCTION [dbo].[F_NUMEROS]
(@STRING VARCHAR(100)
)
RETURNS VARCHAR(100)
AS
     BEGIN
         DECLARE @MAX INT, @CARAC CHAR(1), @NUM VARCHAR(100);
         SET @MAX =
         (
             SELECT LEN(@STRING)
         );
         SET @NUM = '';
         WHILE @MAX > 0
             BEGIN
                 SET @CARAC =
                 (
                     SELECT RIGHT(LEFT(@STRING, LEN(@STRING) - @MAX + 1), 1)
                 );
                 IF @CARAC <> ''
                     BEGIN
                         IF ISNUMERIC(@CARAC) = 1
                             BEGIN
                                 SET @NUM = @NUM + @CARAC;
                         END;
                 END;
                 SET @MAX = @MAX - 1;
             END;
         RETURN @NUM;
     END;
GO