I recently found out that my links stored in the database do not open in new tabs (no target="_blank"). I made this script that adds it in.
My problem is that if the Preamble column has multiple links, only the first one will be updated with target="_blank", how can I run this for all links in the column?
SELECT
STUFF(Preamble, CHARINDEX('>', Preamble, PATINDEX('%<a href%', Preamble)) - 1, 1, '" target="_blank"')
FROM
QuestionContainer
WHERE
Preamble LIKE '%<a href%'
The Preamble column contains other HTML markup and other text.
Update
So for some reason I was trying to add the target="_blank" to the end of the anchor tag, instead I can just add it to the start.
A simple REPLACE(Preamble, '%<a href%', '<a target="_blank" href') will hit all occurrences in a row and solve my problem. - Thanks Allan S. Hansen
update questioncontainer set preamble = replace(preamble, '<a href', '<a href target="_blank" ')not do it? (of course this doesn't take into account those where you've already done it, will need to replace those back first :)) Otherwise you'll need to write a loop / function to split your column and re-work your indexes<a hrefwith to ensure it doesn't trigger on other htmlREPLACE('<a href=some.website/default.asp">Department’s Purchasing and Procurement Instructions</a>', '<a href', '<a target="_blank" href');seems to work and then it's just replacing the actual text with your column and updating