Query to get only numbers from a string

前端 未结 14 2272
野性不改
野性不改 2020-11-22 06:17

I have data like this:

string 1: 003Preliminary Examination Plan   
string 2: Coordination005  
string 3: Balance1000sheet

The output I exp

14条回答
  •  情歌与酒
    2020-11-22 06:23

    Just a little modification to @Epsicron 's answer

    SELECT SUBSTRING(string, PATINDEX('%[0-9]%', string), PATINDEX('%[0-9][^0-9]%', string + 't') - PATINDEX('%[0-9]%', 
                        string) + 1) AS Number
    FROM (values ('003Preliminary Examination Plan'),
        ('Coordination005'),
        ('Balance1000sheet')) as a(string)
    

    no need for a temporary variable

提交回复
热议问题