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
i hope solved problem.
Comments
Post a Comment