Create Table T
(
ID Varchar(10),
NUMBER int
)
Go
insert into T values('001',10)
insert into T values('002',20)
--以下查询结果30条记录,NUMBER在32767以内
With TC
As
(
Select * From T
union All
Select ID,NUMBER-1 From TC Where NUMBER>1
)
Select * From TC
Order by ID,NUMBER
OPTION (MAXRECURSION 32767)