declare @s int declare @i int declare @c char(12) set @s = 1 set @i = 0 while @s <= 100000 begin select @c = right(cast(cast(rand(@i) * 1000000000000 as bigint) + 10000000000000 as varchar), 12) set @i = @i + 1 if not exists (select * from table1 where cardno = @c) begin insert table1 (cardno) values (@c) set @s = @s + 1 end end
tj_dns(愉快的登山者 MVP) 的随机性好吗?
select top 100000 right('000000000000'+cast(卡号+cast(rand(checksum(newid()))*5 as int) as varchar(10)),12) 卡号 from 卡号表 where 卡号%5=0
select top 100000 identity(int,1,5) id into #aa from sysobjects a,sysobjects b,sysobjects c,sysobjects d,sysobjectsselect right('000000000000'+cast(id+cast(rand(checksum(newid()))*5 as int) as varchar(10)),12) 卡号 from #aago drop table #aa
declare @i int
declare @c char(12)
set @s = 1
set @i = 0
while @s <= 100000
begin
select @c = right(cast(cast(rand(@i) * 1000000000000 as bigint) + 10000000000000 as varchar), 12)
set @i = @i + 1
if not exists (select * from table1 where cardno = @c)
begin
insert table1 (cardno) values (@c)
set @s = @s + 1
end
end
from 卡号表
where 卡号%5=0
from #aago
drop table #aa