In SQL Server can you find the first number in a string?

前端 未结 5 898
难免孤独
难免孤独 2021-02-12 10:12

I have a varchar(50) sql server column with data like this:

RawData
----------------------------
Washington 40 New Orleans 32
Detroit 27 St. Louis 23
         


        
5条回答
  •  野的像风
    2021-02-12 10:41

    Is there a way to identify the position of the first number in a string?

    Yes

    SELECT PATINDEX('%[0-9]%','Washington 40 New Orleans 32')
    

    PATINDEX returns 0 if the pattern can't be found or the 1 based index of the beginning of the match otherwise.

提交回复
热议问题