奇怪的NewId(),高手给解释一下
CSDMN 2004-07-20 01:37:49 原问题:http://community.csdn.net/Expert/topic/3191/3191649.xml?temp=.9414789
主 题: 大批量生成随机数的问题
作 者: jjennyj (d)
等 级:
信 誉 值: 100
所属社区: MS-SQL Server 数据库开发
问题点数: 50
回复次数: 7
发表时间: 2004-07-20 11:47:14
我要根据需求随机产生大批量随机数,长度为25位,不过前5位是产品代码无需随机产生,一次需要产生10,000条,还不可以重复。大家给点思路,
---------------------------------------------------------------
第一反映是:
select distinct top 10000 left(newid(),20)
from sysobjects a,sysobjects b,sysobjects c,sysobjects d
结果只得到58条
改成:
select distinct newid()
from sysobjects a,sysobjects b,sysobjects c,sysobjects d
结果还是58条
改成:
select distinct newid()
from (
select a.*
from sysobjects a,sysobjects b,sysobjects c,sysobjects d
) as x
结果还是58条
没办法了,不用sysobjects吧,改成:
select distinct top 10000 left(newid(),20) from
(
select a+b+c+d as [all]
from
(
select 0 as a
union all
select 1
union all
select 2
union all
select 3
union all
select 4
union all
select 5
union all
select 6
union all
select 7
union all
select 8
union all
select 9
) as a,(
select 0 as b
union all
select 1
union all
select 2
union all
select 3
union all
select 4
union all
select 5
union all
select 6
union all
select 7
union all
select 8
union all
select 9
) as b,(
select 0 as c
union all
select 1
union all
select 2
union all
select 3
union all
select 4
union all
select 5
union all
select 6
union all
select 7
union all
select 8
union all
select 9
) as c,(
select 0 as d
union all
select 1
union all
select 2
union all
select 3
union all
select 4
union all
select 5
union all
select 6
union all
select 7
union all
select 8
union all
select 9
) as d
) as x
你们猜我得到几条结果?