Created
April 11, 2019 16:04
-
-
Save PRElias/7b9fbb290ee44fbf809260d9fb7afac5 to your computer and use it in GitHub Desktop.
SQL Server GetNumeric function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****** Object: UserDefinedFunction [dbo].[GetNumeric] Script Date: 11/04/2019 11:51:55 ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
CREATE FUNCTION [dbo].[GetNumeric] | |
(@strAlphaNumeric VARCHAR(256)) | |
RETURNS VARCHAR(256) | |
AS | |
BEGIN | |
DECLARE @intAlpha INT | |
SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric) | |
BEGIN | |
WHILE @intAlpha > 0 | |
BEGIN | |
SET @strAlphaNumeric = STUFF(@strAlphaNumeric, @intAlpha, 1, '' ) | |
SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric ) | |
END | |
END | |
RETURN ISNULL(@strAlphaNumeric,0) | |
END | |
GO | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment