--要自己写:--自定义函数:取得指定上下限的随机数if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_rand]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[f_rand]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[v_rand]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[v_rand]
GO--需要这样一个视图
create view v_rand as select re=rand()
go--自定义函数:取得指定上下限的随机数
create function f_rand(
@下限 int,
@上限 int
)
returns decimal(38,0)
as
begin
declare @r decimal(38,0)
select @r=cast(re*(@上限-@下限)+@下限 as decimal(38,0)) from v_rand
return(@r)
end
go--调用示例
select dbo.f_rand(10,100),dbo.f_rand(10,100)

解决方案 »

  1.   

    给你个例子看看,每次取出来的ID就是随机的
    declare @ table(id int)
    insert @ select 1 union select 2select top 1 id from  @ order by newid()
      

  2.   

    create table t(a int)
    insert into t select 2
    insert into t select 21
    insert into t select 22
    insert into t select 25
    insert into t select 42
    select top 1 * from t order by newid()
    drop table t
      

  3.   

    上面的copy至查询分析器,然后不停的安F5