if OBJECT_ID('fn_test') is not null drop function fn_test go create function fn_test(@s varchar(100)) returns varchar(100) as begin while patindex('%<%>%',@s)>0 select @s=stuff(@s,patindex('%<%>%',@s),charindex('>',@s)-charindex('<',@s)+1,'') return @s end go declare @s varchar(100) set @s='AABB<CC>DCCCEE<C><CCCCCC>' select dbo.fn_test(@s) /* ---------------------------------------------------------------------------------------------------- AABBDCCCEE(1 行受影响) */
非常感谢,刚刚突然想明白,原来在语句中也可以用 '<0000>' like '<%0%>' 这样的判断,而不必在where中使用,,,惭愧,悟性太低了
if OBJECT_ID('fn_test') is not null
drop function fn_test
go
create function fn_test(@s varchar(100))
returns varchar(100)
as
begin
while patindex('%<%>%',@s)>0
select @s=stuff(@s,patindex('%<%>%',@s),charindex('>',@s)-charindex('<',@s)+1,'')
return @s
end
go
declare @s varchar(100)
set @s='AABB<CC>DCCCEE<C><CCCCCC>'
select dbo.fn_test(@s)
/*
----------------------------------------------------------------------------------------------------
AABBDCCCEE(1 行受影响)
*/