sql如何获取一个0-15之间的随机数(不包括0,15),而且必须带两位随机的小数

来源:互联网 发布:结构力学分析软件 编辑:程序博客网 时间:2024/04/30 13:23

Select cast(rand() * 15 as decimal(18,2))

 

declare @num float
select @num=rand()*15
select substring(cast(@num as varchar(20)),0,charindex('.',@num)+3)

--根据 时间种子 随机生成
select convert(decimal(8,2),15*rand(datepart(ms,getdate())+ datepart(ss,getdate())*1000))

--运行代码看结果
declare @n int
declare @f decimal(18,2)

set @n=cast(rand()*1499 as int )+1--@n in ( 1,2,3,...,1499 )
set @f = @n
set @f = @f / 100--@f in ( 0.01,...14.99 )

select @f--结果