SQL Server : remove duplicated text within a string -


i have sql server 2008 table column containing lengthy html text. near top there link provided associated mp3 file unique each record. links are formatted follows:

<div class="mediasaveas"><a href="filename??.mp3">download audio </a></div> 

unfortunately many records contain 2 or 3 sequential , identical instances of link there should one. there relatively simple script can run find , eliminate redundant links?

i'm not entirely sure - because explanation wasn't clear - appears want, although whether or not consider "simple script", don't know.

declare @link nvarchar(200) = n'<div class="mediasaveas"><a href="filename123.mp3">download audio </a></div>'  declare @baddata nvarchar(max) = n'cbjahcgfhjasgfzhjaucv' + replicate(@link, 3) + n'cabhjcsghagj',         @startpattern nvarchar(34) = n'<div class="mediasaveas"><a href="',         @endpattern nvarchar(27) = n'">download audio </a></div>'  select @baddata  select replace (     @baddata,     substring(@baddata, charindex(@startpattern, @baddata), len(@baddata)-charindex(reverse(@endpattern), reverse(@baddata))-charindex(@startpattern, @baddata) + 2),     substring(@baddata, charindex(@startpattern, @baddata), charindex(@endpattern, @baddata) + len(@endpattern) - charindex(@startpattern, @baddata)) ) 

personally not have maintain code; far rather use script in language can parse html. said "just repeated text issue", doesn't mean it's easy problem , not in language tsql has such limited support string operations.

for future reference, please put relevant information question - can edit if need - instead of leaving them in comments difficult read , may overlooked. , please post sample data , results instead of describing things in words.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -