SQL只获取varchar(Substring)中的数值

时间:2014-09-24 11:09:04

标签: mysql sql substring varchar patindex

我有这个varchar字段;

Substrg
--------
38-40week
8month
7
40
38-40week

我想只获取数字,例如:

38-40
8
7
40
38-40

我试过这个,但它不起作用......:

select SUBSTRING(Substrg, PATINDEX('%[0-9]%', Substrg), LEN(Substrg))

我该怎么办?感谢

1 个答案:

答案 0 :(得分:3)

select  replace ('38-40week', SUBSTRING('38-40week', PATINDEX('%[a-z]%', '38-40week'), 
LEN('38-40week')),'')