• dan-572483 (8/24/2012)


    If the length of the string might vary - but there will always be brackets - this will work:

    declare @string varchar(max)

    set @string = '{String you want to remove from the brackets}'

    select SUBSTRING(@string, CHARINDEX('{',@string)+1,Charindex('}',@string)-2)

    Dan,

    just out of curiousity-whats the logic behind using '-2' instead of '-1' with charindex.You need to use-2 even if you use len(@string). Whats the logic? I am guessing its because of +1 at the start position-but why? Thanks.