Sqlserver With as 实现循环递归

一、脚本示例

declare @Separator varchar(10), @str varchar(100)
declare @l int, @i int
select @Separator=',',@str='111,22,777,99,666'
select @i = len(@Separator), @l = len(@str);
with cte7 as
(
select 0 a, 1 b union all
select b, charindex(@Separator, @str, b)+@i
from cte7 where b > a
)
select * from cte7

二、结果

 

posted @ 2025-01-01 18:02  寻天崖子  阅读(2)  评论(0编辑  收藏  举报