2015-03-03 74 views
-2

我想在SQL Server中通過刪除其所有html內容來更新數據。刪除並替換SQL中的所有html內容

請參閱下面的示例數據。

這是一個示例文本。

<html><head></head><body><p>This is a sample text.</p></body></html> 

我只需要保留純文本並刪除所有這些HTML內容,包括標籤。我認爲,參考可能從<html**/html >

有什麼建議嗎?

+0

使用替換功能,您可以通過此功能,以空格代替<, 2015-03-03 04:53:30

回答

0

Charindex + While Loop。嘗試這個。

DECLARE @html VARCHAR(5000)='This is a sample text <html><head></head ><body><p>This is a sample text.<p></body></html>', 
     @start INT, 
     @end INT 

WHILE Charindex('<', @html) > 0 
    BEGIN 
     SET @start= Charindex('<', @html) 
     SET @end = Charindex('>', @html) 

     SELECT @html = Stuff(@html, @start, (@end - @start) + 1, '') 
    END 

SELECT @html --This is a sample text This is a sample text. 
+0

您好,感謝,將在應用到具有HTML的所有行? 每個記錄都有純文本版本以及它的html版本。 – Mark 2015-03-04 05:30:35

+0

這將刪除< and >之間的所有詞 – 2015-03-04 05:32:17