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!
注意:调用时有可能会遇到如下提示:'ReplaceHTML' 不是可以识别的 内置函数名称 这时需要在 函数名前+dbo.,即:dbo.ReplaceHTML('aaaa')
转载于:https://www.cnblogs.com/xxj-jing/archive/2012/06/12/2890062.html