-1

I've got data in sql server 2012 that contains text with links <a href="test/test">test </a> with out target i need to add target for the string data. I need to create a User defined function for that. Does any one have any sample code for this.

Example text -

If you've ever thought one of your text message threads was so good it deserved to be published, you may be on to something.view. <a href="/apple/sdffsd/sdffs">njkhj </a> In future iterations, users will be able to post .<br><br>You may update your email address at any time by going to <a href="/apple/fafasdf/sdfsdf">sdffsd</a>. Our whole goal is to have the reader go through an entire narrative arc in five minutes and consume it in a way that's native to mobile," says Gupta go to <a href="/a/s/sdfsf"> sdfsdf </a> which is one of my favorite books, is told as letters back and forth between the two main

3
  • What have you researched, tried, and found to not work? SO is not a place where you ask for a tailored solution while showing zero effort on your part. Commented Oct 10, 2016 at 13:52
  • please elaborate on target i need to add target Commented Oct 10, 2016 at 13:56
  • As the target='_blank' is useless outside a browser, could you not manage that in your application ? Something like that : stackoverflow.com/questions/7901679/… ? Commented Oct 10, 2016 at 14:01

2 Answers 2

1

I think a simple replace would do the trick

Declare @String varchar(max) = 'Some large text with a <a href="test/test">link</a> to content' Select Replace(@String,' href=','_target="blank" href=') 

Returns

(No column name) Some large text with a <a _target="blank" href="test/test">link</a> to content 
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. I thought the same... I realized that i was over complicating things and just needed to think simple.
@akki Always too easy to over think things
Did not use stack over flow a lot , where can i mark it as answered?
@akki near the Up/Down Vote
0

We can also use SELECT REPLACE(text,'<a','<a target="_blank" '); Go

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.