日期:2014-05-17 浏览次数:20465 次
CREATE TABLE #temp(ID INT)
DECLARE @ID INT,@Count int
select @ID=5000,@Count=4
;WITH a1 AS
(
SELECT @ID id,1 n
UNION ALL
SELECT ID-1,n+1 FROM a1
WHERE n<@Count
)
INSERT #temp
SELECT id FROM a1
SELECT * FROM #temp
declare @id int
declare @count int
declare @tb table(id int,c int)
insert into @tb
select 5000,4 union all
select 4999,4 union all
select 4998,4 union all
select 4997,4
select v.*
from @tb v,master..spt_values t
where t.type = 'P' and t.number > 0 and t.number <= v.c
/*
id c
5000 4
5000 4
5000 4
5000 4
4999 4
4999 4
4999 4
4999 4
4998 4
4998 4
4998 4
4998 4
4997 4
4997 4
4997 4
4997 4
*/