Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How can i extract numeric values from varchar

How can i extract numeric values from varchar

Scheduled Pinned Locked Moved Database
question
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    snehasish
    wrote on last edited by
    #1

    hi all; I want to extract only numeric values from a column which have alphanumeric values like ABC12342M , AE2213Jk. Thanks Snehasish

    B 1 Reply Last reply
    0
    • S snehasish

      hi all; I want to extract only numeric values from a column which have alphanumeric values like ABC12342M , AE2213Jk. Thanks Snehasish

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      You should create function which loops every character in string and check if is number or not.


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

      S 1 Reply Last reply
      0
      • B Blue_Boy

        You should create function which loops every character in string and check if is number or not.


        I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

        S Offline
        S Offline
        snehasish
        wrote on last edited by
        #3

        hi; Many thanks for reply.It must work.But It will be lengthy process as per my application.So if you give any other soln,that will be helpful. Thanks snehasish

        B 1 Reply Last reply
        0
        • S snehasish

          hi; Many thanks for reply.It must work.But It will be lengthy process as per my application.So if you give any other soln,that will be helpful. Thanks snehasish

          B Offline
          B Offline
          Blue_Boy
          wrote on last edited by
          #4

          Well here is function which return only numbers from given string parameter. CREATE FUNCTION [dbo].[ReturnNumber](@Parametri VARCHAR(8000)) returns varchar(8000) as begin declare @i as int set @i=0 declare @resultNumber as varchar(8000) while(@i<=len(@Parametri)) begin set @i=@i+1 if(select isnumeric(substring(@Parametri,@i,1)))=1 begin set @resultNumber =@resultNumber+substring(@Parametri,@i,1) end end return @resultNumer END


          I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

          S 1 Reply Last reply
          0
          • B Blue_Boy

            Well here is function which return only numbers from given string parameter. CREATE FUNCTION [dbo].[ReturnNumber](@Parametri VARCHAR(8000)) returns varchar(8000) as begin declare @i as int set @i=0 declare @resultNumber as varchar(8000) while(@i<=len(@Parametri)) begin set @i=@i+1 if(select isnumeric(substring(@Parametri,@i,1)))=1 begin set @resultNumber =@resultNumber+substring(@Parametri,@i,1) end end return @resultNumer END


            I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

            S Offline
            S Offline
            snehasish
            wrote on last edited by
            #5

            hi; many thanks :) .I can not find any wrong in your function "ReturnNumber". but when i input a varchar, for example 'AA432k', it returns a null value. This is my query:

            select dbo.ReturnNumber('AA432k')

            or

            select dbo.ReturnNumber(varcharcolumn) from test

            what is my wrong? snehasish

            B 1 Reply Last reply
            0
            • S snehasish

              hi; many thanks :) .I can not find any wrong in your function "ReturnNumber". but when i input a varchar, for example 'AA432k', it returns a null value. This is my query:

              select dbo.ReturnNumber('AA432k')

              or

              select dbo.ReturnNumber(varcharcolumn) from test

              what is my wrong? snehasish

              B Offline
              B Offline
              Blue_Boy
              wrote on last edited by
              #6

              After declaring of variable @resultNumber then initiliaze it with empty string. . . . declare @resultNumer as varchar(8000) **set @resultNumer =''** . . .


              I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups