App Muncher

Issues faced - solutions identified - shared with community.

Create a function in your database to remove html tags in SELECT statement.

Use this function in select's to trim html tags.


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

No comments:

Post a Comment

| Designed by AppMuncher