Sunday 26 March 2017

Extract only numeric from alphanumeric string

With the help of below sql script we can find the only numeric from the given string.
Declare @s varchar(100),@result varchar(100)
set @s='bageshkumarsingh12346@gmail.com'
set @result=''
select  @result=@result+case when number like '[0-9]' then number else '' end
    from
    (
         select substring(@s,number,1) as number from
        (
            select number from master..spt_values where type='p' and
                   number between 1 and len(@s)
        ) as t
    ) as t
select @result as Result


See the result
  

No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts