首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

关于读取入位随机数的有关问题

2012-02-21 
关于读取入位随机数的问题selectcast((rand())*10000000asint)但是这种情况有可能,第一位是0的现象,如0254

关于读取入位随机数的问题
select   cast((rand())   *10000000   as   int)
但是这种情况有可能,第一位是0的现象,如02547415,系统显示成7位,大家有没什么办法左补0,如果是第一二们是0,就补两个0

[解决办法]
select right( '00000000 '+cast(cast((rand()) *10000000 as int) as varchar(20)),8)
[解决办法]
select right( '00000000 '+ ltrim(cast((rand()) *10000000 as int)),8)
[解决办法]
declare @str varchar(8)
declare @i int 0
while @i < 8 - len(cast(cast((rand()) *10000000 as int)) as varchar(8)))
begin
select @str += '0 '
@i++
end
if len(cast(cast((rand()) *10000000 as int)) as varchar(8))) <8
begin
select @str = @str + cast(cast((rand()) *10000000 as int)) as varchar(8))
end
else
select @str = cast(cast((rand()) *10000000 as int)) as varchar(8))

热点排行
Bad Request.