日期:2014-05-18 浏览次数:20586 次
create function fn_fulfill (@find varchar(200), @Field varchar(200),@find1 varchar(200), @Field1 varchar(200)) returns int as begin declare @return int declare @pos int,@pos1 int if( @find='' and @find1='') begin set @return=1 end else begin declare @t table(pos int) declare @t1 table(pos int) select @pos=charindex(','+@find+',',','+@Field+','),@pos1=charindex(','+@find1+',',','+@Field1+',') if @pos>0 and @pos1>0 begin while @pos>0 begin insert @t select @pos select @pos=charindex(','+@find+',',','+@Field+',',@pos+1) end while @pos1>0 begin insert @t1 select @pos1 select @pos1=charindex(','+@find1+',',','+@Field1+',',@pos1+1) end if exists(select 1 from @t a,@t1 b where a.pos=b.pos) set @return=1 else set @return=0 end else set @return=0 end return(@return) end
------解决方案--------------------
create function fn_fulfill (@find varchar(200), @Field varchar(200),@find1 varchar(200), @Field1 varchar(200)) returns int as begin declare @return int declare @index int declare @index_old int set @return = 0 set @index_old = 0 set @index = 0 if( len(@find) > 0 and len(@find1) > 0) begin while 1=1 begin set @index = charindex(@find,@field,@index) if @index = @index_old break else set @index_old = @index if charindex(@find1,@Field1,@index) > 0 begin set @return = 1 break end --if end; --while end else --if set @return = 1 return(@return) end
------解决方案--------------------
更正:
create function fn_fulfill (@find varchar(200), @Field varchar(200),@find1 varchar(200), @Field1 varchar(200)) returns int as begin declare @return int declare @index int declare @index_old int set @return = 0 set @index_old = 0 set @index = 0 if( len(@find) > 0 and len(@find1) > 0) begin while 1=1 begin set @index = charindex(@find,@field,@index) if @index =