今天晚上学习了下 SQL 基于关系的运算,同时也捉摸着写了个例子,虽然我知道性能不是很好,还有待优化。直接上源代码吧,思路表达出来有点困难,直接贴上代码,如果有人不懂得可以MM 我。
declare @table table(n int)
declare @c int
set @c= 1 while @c<50
begin
insert into @table values(@c) set @c=@c+1
end declare @inp varchar(200),@len int,@spl varchar(10)
set @inp = '22,32003,11,22'
set @spl=',' --set @spl=','
set @len =LEN(@spl) select SUBSTRING(s,ISNULL(n2+@len,1),n1 - ISNULL(n2+@len,1)) item from (
select t1.s,t1.n n1,t2.n n2
from (
select ROW_NUMBER() over(order by n ) as row, * from ( select @inp as s ) s
inner join @table Nums on Nums.n <= (LEN(@inp)+@len)
and SUBSTRING(s+@spl,n,@len) = @spl
) t1
left join
(
select ROW_NUMBER() over(order by n ) as row, * from ( select @inp as s ) s
inner join @table Nums on Nums.n <= (LEN(@inp)+@len)
and SUBSTRING(s+@spl,n,@len) = @spl
) t2
on t1.row -1 =t2.row
) tt
上面的代码可以直接复制运行。
刚刚发现这个富文本的编辑框很不错,找个时间研究下。 学无止境。