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

前端 未结 5 714
孤街浪徒
孤街浪徒 2021-02-12 09:53

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:45

    my query for selecting multi-didget numbers out of a url (ignore rows without a number and rows where the number is after the '?'

    select 
        URL,
        substring(URL,PATINDEX ('%[0-9][0-9][0-9][0-9][0-9][0-9][0-9]%',URL),7) as id
    from data 
    where 
        PATINDEX ('%[0-9][0-9][0-9][0-9][0-9][0-9][0-9]%',URL)>0 
    and PATINDEX ('%[0-9][0-9][0-9][0-9][0-9][0-9][0-9]%',URL)

提交回复
热议问题