Advertisement
Guest User

[dbo].[udf_GetNumeric]

a guest
Jan 17th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.55 KB | None | 0 0
  1. /****** Object:  UserDefinedFunction [dbo].[udf_GetNumeric]    Script Date: 1/17/2018 3:54:02 PM ******/
  2. SET ANSI_NULLS ON
  3. GO
  4.  
  5. SET QUOTED_IDENTIFIER ON
  6. GO
  7.  
  8. CREATE FUNCTION [dbo].[udf_GetNumeric]
  9. (@strAlphaNumeric VARCHAR(256))
  10. RETURNS VARCHAR(256)
  11. AS
  12. BEGIN
  13. DECLARE @intAlpha INT
  14. SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric)
  15. BEGIN
  16. WHILE @intAlpha > 0
  17. BEGIN
  18. SET @strAlphaNumeric = STUFF(@strAlphaNumeric, @intAlpha, 1, '' )
  19. SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric )
  20. END
  21. END
  22. RETURN ISNULL(@strAlphaNumeric,0)
  23. END
  24.  
  25. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement