Sql,返回随机数

返回一个10-1000的随机数:

declare   @M   int,@N   int
set   @N=10
set   @M=1000
declare @t int
declare @i int
set @i=0
while(@i<10000)
begin
    select  @t=cast((rand()*(@M-@N+1)+@N)   as   int)
    if(@t=10)
    begin
        select @t
    end
    set @i=@i+1
end

返回一个10-999的随机数:
declare   @M   int,@N   int
set   @N=10
set   @M=1000
declare @t int
declare @i int
set @i=0
while(@i<10000)
begin
    select  @t=cast((rand()*(@M-@N)+@N)   as   int)
    if(@t=10)
    begin
        select @t
    end
    set @i=@i+1
end
 
原文地址:https://www.cnblogs.com/mxw09/p/2028979.html