How to extract this specific substring in SQL Server?

前端 未结 5 2273
慢半拍i
慢半拍i 2020-12-03 18:04

I have a string with a specific pattern:

23;chair,red [$3]

i.e., a number followed by a semicolon, then a name followed by a left square br

5条回答
  •  盖世英雄少女心
    2020-12-03 18:41

    Assuming they always exist and are not part of your data, this will work:

    declare @string varchar(8000) = '23;chair,red [$3]'
    select substring(@string, charindex(';', @string) + 1, charindex(' [', @string) - charindex(';', @string) - 1)
    

提交回复
热议问题