2016-10-10 35 views
-1

我在sql server 2012中獲得了包含帶鏈接文本的數據<a href="test/test">test </a>無目標我需要爲字符串數據添加目標。我需要爲此創建一個用戶定義的函數。有沒有人有這樣的示例代碼。使用UDF在字符串中爲href添加目標='_ blank'的最佳方式

示例文本 -

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="https://stackoverflow.com/a/s/sdfsf"> sdfsdf </a> which is one of my favorite books, is told as letters back and forth between the two main

+0

你有什麼研究,嘗試過,發現不起作用? SO並不是您要求量身定製的解決方案的地方,同時您也毫不費力。 – dfundako

+0

請詳細說明目標'我需要添加目標' – TheGameiswar

+0

由於'target ='_ blank''在瀏覽器外部是無用的,您是否可以在應用程序中管理它?就像那樣:http://stackoverflow.com/questions/7901679/jquery-add-target-blank-for-outgoing-link? –

回答

1

我認爲一個簡單的更換會做的伎倆

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

Select Replace(@String,' href=','_target="blank" href=') 

返回

(No column name) 
Some large text with a <a _target="blank" href="test/test">link</a> to content 
+0

謝謝。我也是這樣想的......我意識到我過於複雜,只需要簡單思考。 – akki

+0

請將此標記爲已回答 – akki

+0

@akki總是太容易想到事情 –

0

我們也可以使用 SELECT REPLACE(text,'<a','<a target="_blank" '); Go

相關問題