Last active
March 3, 2016 17:06
-
-
Save azborgonovo/9120640 to your computer and use it in GitHub Desktop.
SQL Server Function for stripping Html tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION [dbo].[udf_StripHTML](@HTMLText VARCHAR(MAX)) | |
RETURNS VARCHAR(MAX) | |
AS | |
BEGIN | |
DECLARE @Start INT | |
DECLARE @End INT | |
DECLARE @Length INT | |
SET @Start = CHARINDEX('<',@HTMLText) | |
SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText)) | |
SET @Length = (@End - @Start) + 1 | |
WHILE @Start > 0 | |
AND @End > 0 | |
AND @Length > 0 | |
BEGIN | |
SET @HTMLText = STUFF(@HTMLText,@Start,@Length,'') | |
SET @Start = CHARINDEX('<',@HTMLText) | |
SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText)) | |
SET @Length = (@End - @Start) + 1 | |
END | |
RETURN LTRIM(RTRIM(@HTMLText)) | |
END | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment