请教一个批量生成数据的问题
两个参数,@ID是数据,@Count生成数据的行数
比例@ID=5000,@Count=4
批量生成
5000
4999
4998
4997
语句怎么写,有没有效率高的写法,我试过用Row_Number不行,因为没有主键。Identify()可以吗?
[解决办法]
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
/*
idc
50004
50004
50004
50004
49994
49994
49994
49994
49984
49984
49984
49984
49974
49974
49974
49974
*/