1.创建函数脚本

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:
-- Create date:
-- Description: 替换字段中的HTML标签标签内的属性,保留标签对包含的内容
-- =============================================
CREATE FUNCTION ReplaceHTML
(
 @source nvarchar(4000) --原字符串
)
RETURNS nvarchar(4000)
AS
BEGIN
 declare @html nvarchar(1000)
 set @html = @source
 while CHARINDEX('<',@html)>0
 set @html=STUFF(@html,charindex('<',@html),charindex('>',@html)-charindex('<',@html)+1,'')
 return (@html)
END
GO

2.函数调用实例


declare @html nvarchar(1000)
set @html='<a>http://www.iqingcao.com</a><input><font color=red>你好</font><select>afs<p>世界<hr>fasd<object>!<img>'
select dbo.ReplaceHTML(@html);

--执行结果

http://www.***.com你好afs世界fasd!

 

这个其实就是现有函数的活学活用。。

 

转:http://blog.csdn.net/xxj_jing/article/details/7655278

posted on 2014-04-25 14:49  小草原  阅读(233)  评论(0)    收藏  举报