In this article, we learn about SQL Server database functions, and using these functions gets the numeric value from a string value. Most useful functions when we develop applications database like profile related employees code generation, etc. 


SQL Server function for get numeric value from a string:

CREATE FUNCTION GetNumericFromString(@StringValue VARCHAR(256))
RETURNS VARCHAR(256)
AS
BEGIN
  DECLARE @NumericValue INT
  SET @NumericValue = PATINDEX('%[^0-9]%', @StringValue)
  BEGIN
    WHILE @NumericValue > 0
    BEGIN
      SET @StringValue = STUFF(@StringValue, @NumericValue, 1, '' )
      SET @NumericValue = PATINDEX('%[^0-9]%', @StringValue )
    END
  END
  RETURN ISNULL(@StringValue,0)
END;

Call function for getting numeric value from a string:

DECLARE @StringValue VARCHAR(256)='EMPZP20';
SELECT dbo.GetNumericFromString(@StringValue);

Advertisement

5 comments:

  1. What an extremely wonderful post this is. Genuinely, perhaps the best post I've at any point seen to find in as long as I can remember. Goodness, simply keep it up.
    360DigiTMG supply chain analytics course

    ReplyDelete
  2. I'm cheerful I found this blog! Every now and then, understudies need to psychologically the keys of beneficial artistic articles forming. Your information about this great post can turn into a reason for such individuals.
    https://360digitmg.com/course/certification-program-in-data-science

    ReplyDelete
  3. Through this post, I realize that your great information in playing with all the pieces was exceptionally useful. I advise this is the primary spot where I discover issues I've been scanning for. You have a smart yet alluring method of composing.
    data science course in noida

    ReplyDelete
  4. Especially superb!!! Exactly when I search for this I found this webpage at the top of every single online diary in web crawler.
    360DigiTMG

    ReplyDelete
  5. This post is very simple to read and appreciate without leaving any details out. Great work!
    data analytics training aurangabad

    ReplyDelete

 
Top