• bitbucket-25253 (2/8/2010)


    Without using a Tally table

    DECLARE @What VARCHAR(200)

    DECLARE @Start INT

    DECLARE @End Int

    SET @What = 'Sometimes things may get [SQL GETDATE()] heated[comment:#super hot debate].'

    SET @Start = CHARINDEX('[COMMENT',@What,1)

    SET @End = CHARINDEX(']',@What,@Start+1)

    SELECT @Start,@End

    SELECT SUBSTRING(@What,1,@Start-1) + SUBSTRING(@What,@Start+1,LEN(@What)-(@End +1))

    Result:

    Sometimes things may get [SQL GETDATE()] heated

    Is this what you are looking for?

    Hi Ron

    kind of yes ... but needs to run in an SQL SELECT statement as there will be multiple occurences of [comment#...] in the same varchar(max) text column.