Extract first number value from string sql

后端 未结 1 1748
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-16 17:42

I have found many answers that have pointed me on the right track for what I want, like this.

However, if I had a string like \"this attachment will be 22 in. x 15 i

1条回答
  •  清酒与你
    2021-01-16 18:24

    Assuming there really is a number in the string, you can use patindex():

    select left(s, patindex('%[^0-9]%', s) - 1)
    from (select substring(col, patindex('%[0-9]%', col), len(col)) as s
          from t
         ) t;
    

    0 讨论(0)
提交回复
热议问题