 -- =============================================
-- =============================================
 -- Author:        Derry
-- Author:        Derry
 -- Create date: 2009-07-27
-- Create date: 2009-07-27
 -- Description:    去除HTML标签
-- Description:    去除HTML标签
 -- =============================================
-- =============================================
 ALTER FUNCTION [dbo].[StripAllTags]
ALTER FUNCTION [dbo].[StripAllTags]
 (
(
 @input    VARCHAR(8000)
    @input    VARCHAR(8000)
 )
)
 RETURNS VARCHAR(8000)
RETURNS VARCHAR(8000)
 AS
AS
 BEGIN
BEGIN
 declare
    declare 
 @Result varchar(8000),
    @Result varchar(8000),
 @start int,
    @start int,
 @end int,
    @end int,
 @len int
    @len int

 set @input = @input+'<>'
    set @input = @input+'<>'
 set @Result = ''
    set @Result = ''
 set @len=len(@input)
    set @len=len(@input)
 set @start = charindex('<',@input,1)
    set @start = charindex('<',@input,1)
 set @end = charindex('>',@input,@start)
    set @end = charindex('>',@input,@start)
 while(@start<@end)
    while(@start<@end)
 begin
        begin        
 if(@start<>1)
            if(@start<>1) 
 set @Result = @Result + substring(@input,1,@start-1)
              set @Result = @Result + substring(@input,1,@start-1)
 set @len = @len - @end
            set @len = @len - @end
 set @input = substring(@input,@end+1,@len)
            set @input = substring(@input,@end+1,@len)
 set @start = charindex('<',@input,1)
            set @start = charindex('<',@input,1)
 set @end = charindex('>',@input,@start)
            set @end = charindex('>',@input,@start)
 end
        end

 RETURN replace(@Result,' ','')
    RETURN replace(@Result,' ','')    
 END
END转载于:https://www.cnblogs.com/hailibu/archive/2009/07/27/1532127.html