sql - Query to get only numbers from a string -


suppose have data this:

string 1: 003preliminary examination plan    string 2: coordination005   string 3: balance1000sheet 

the output expect

string 1: 003 string 2: 005 string 3: 1000 

and want implement in sql. please help. in advance :)

first create udf

create function dbo.udf_getnumeric (@stralphanumeric varchar(256)) returns varchar(256) 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 

now use function as

select dbo.udf_getnumeric(column_name)  table_name 

sql fiddle

i hope solved problem.

reference


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -