This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I have created one user defined function to remove all HTML tags from the string data of SQL Server.
There are certain requirements like, store HTML document into the text column, but unfortunately it also contains HTML tags which required to remove.
I have found one user defined function to remove all HTML Tags from the given string.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
CREATE FUNCTION dbo.RemoveHTML (@HTMLData VARCHAR(MAX)) RETURNS VARCHAR(MAX) AS BEGIN DECLARE @HTMLDataXML XML DECLARE @ResultData VARCHAR(MAX) SET @HTMLDataXML = REPLACE( @HTMLData, '&', '' ); WITH HTMLDoc(texts) AS ( SELECT chunks.chunk.query('.') FROM @HTMLDataXML.nodes('/') AS chunks(chunk) ) SELECT @ResultData = texts.value('.', 'varchar(max)') FROM HTMLDoc RETURN @ResultData END GO |
Sample Execution:
1 |
SELECT dbo.RemoveHTML(' This is a Database Research and Development ') |