日期:2014-05-18 浏览次数:20568 次
A,B,C,D,E,F,J,H,I,J,K,L,M,N,O,P,Q,
A,B,C,<A>D,E,F,<A>J,H,I,<A>M,N,O,<A>P,Q,
declare @a varchar(100),@b varchar(100),@i int select @a='A,B,C,D,E,F,J,H,I,J,K,L,M,N,O,P,Q,',@b='',@i=0 while @i<len(@a)/6 begin set @b=@b+substring(@a,@i*6+1,6)+'<A>' set @i=@i+1 end select @b=@b+substring(@a,len(@a)/6*6,len(@a)-len(@a)/6*6) select @b /* ---------------------------------------------------------------- A,B,C,<A>D,E,F,<A>J,H,I,<A>J,K,L,<A>M,N,O,<A>,P,Q (1 行受影响) */
------解决方案--------------------
declare @a varchar(100),@b varchar(100),@c varchar(100),@i int select @a='A,B,C,D,E,F,J,H,I,J,K,L,M,N,O,P,Q,',@b='',@i=1,@c=@a while @i<=len(@a)-len(replace(@a,',','')) begin if(@i%3=0) set @b = @b + substring(@c,1,charindex(',',@c)-1) + ',<A>' else set @b = @b + substring(@c,1,charindex(',',@c)-1) + ',' set @c = substring(@c,charindex(',',@c)+1,len(@c)-charindex(',',@c)) set @i=@i+1 end select @b