-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

Nethra
  • 51
  • 4
  • 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. – dfundako Oct 10 '16 at 13:52
  • please elaborate on target `i need to add target` – TheGameiswar Oct 10 '16 at 13:56
  • As the `target='_blank'` is useless outside a browser, could you not manage that in your application ? Something like that : http://stackoverflow.com/questions/7901679/jquery-add-target-blank-for-outgoing-link ? – Raphaël Althaus Oct 10 '16 at 14:01

2 Answers2

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
John Cappelletti
  • 79,615
  • 7
  • 44
  • 66
0

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

Nethra
  • 51
  • 4