Find a specific substring using Transact-SQL

后端 未结 6 638
孤独总比滥情好
孤独总比滥情好 2021-01-27 06:24

I need to pull a specific substring from a string of the form:

foo=abc;bar=def;baz=ghi

For example, how would I get the value of \"bar\" from t

6条回答
  •  面向向阳花
    2021-01-27 07:18

    this is assuming that the string will have the same string format just substitute the column name for the 'foo=abc;bar=def;baz=ghi'

    select substring('foo=abc;bar=def;baz=ghi',patindex('%bar=%','foo=abc;bar=def;baz=ghi')+4, len('foo=abc;bar=def;baz=ghi')-patindex('%;baz=%','foo=abc;bar=def;baz=ghi')-4)
    

提交回复
热议问题