gravitysucks (8/25/2012)
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.
the actual syntax is :
SUBSTRING ( expression ,start , length )
here the length is how many characters of the expression is returned ; i.e the new string length expected.
as CharIndex on } gives the total length of the initial string, -2 is done to get total length of new string.
~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one :ermm: