Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql extract numbers from string

CREATE FUNCTION dbo.udf_GetNumeric
(
  @strAlphaNumeric VARCHAR(256)
)
RETURNS VARCHAR(256)
AS
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

//////////

USAGE:
SELECT dbo.udf_GetNumeric(column_name) 
from table_name
Comment

PREVIOUS NEXT
Code Example
Sql :: create table in sql 
Sql :: sql create schema 
Sql :: Get monday of week date is in SQL 
Sql :: sql alter type of column 
Sql :: get all columns from table sql 
Sql :: how to change a collumn name in sql 
Sql :: check if database exists sql 
Sql :: ms sql print from new line 
Sql :: select last row mysql 
Sql :: delete row psql 
Sql :: sql case 
Sql :: sqlite show table indexes 
Sql :: how to calculate number of days between two dates excluding weekends in oracle 
Sql :: how to transfer pandas datafra,e to sqlite 
Sql :: how to combine first and last nae into one columb sql 
Sql :: read all columns of a table sql 
Sql :: mysql union 
Sql :: RowDataPacket 
Sql :: varchar vs nvarchar sql 
Sql :: what is default mysql database password in linux 
Sql :: sort by sql 
Sql :: sql count null as 0 
Sql :: how to uninstall postgresql 13 on mac 
Sql :: sql server insert into table 
Sql :: alter table add column in sql server 
Sql :: sql show table info 
Sql :: date in oracle 
Sql :: select * where id = 1,2,3 
Sql :: error code 1215 cannot add foreign key constraint 
Sql :: enable full text search mysql 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =