Find a specific substring using Transact-SQL

后端 未结 6 734
孤独总比滥情好
孤独总比滥情好 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:30

    This can achieve in simple way

    DECLARE  @str VARCHAR(30)
    
    DECLARE  @start INT
    
    SET @str='foo=abc;bar=def;baz=ghi'
    
    SET @start=CHARINDEX('bar',@str)
    
    PRINT SUBSTRING(@str,@start,3)
    

提交回复
热议问题