We've done this a few times here, usually with a loop. I thought I'd give a go using a numbers table.if object_id('dbo.ufn_StripHTML') is not nullbegin drop function dbo.ufn_StripHTMLendgocreate function dbo.ufn_StripHTML ( @Input varchar(8000), @Delimiter char(1) )returns varchar(8000)asbegin declare @Output varchar(8000) select @Input = replace(replace(@input, '<', @Delimiter), '>', @Delimiter) select @Output = isnull(@Output, '') + s from ( select row_number() over (order by n.n asc) [i], substring(@Delimiter + @Input + @Delimiter, n.n + 1, charindex(@Delimiter, @Delimiter + @Input + @Delimiter, n.n + 1) - n.n - 1) [s] from dbo.Number n where n.n = charindex(@Delimiter, @Delimiter + @Input + @Delimiter, n.n) and n.n <= len(@Delimiter + @Input) ) d where i % 2 = 1 return @Outputendgoselect dbo.ufn_StripHTML('<a>1<b>2</b>3<c>4<d ddd="ddd"><>5<5>', '|')goif object_id('dbo.ufn_StripHTML') is not nullbegin drop function dbo.ufn_StripHTMLend