八位吧?--8位随机数的生成
select id = right('00000000' + cast(cast(rand(checksum(newid()))*10000000 as int) as varchar),8) from sysobjectsid               
---------------- 
01934411
05928993
01997233
03088228
05414214
07259494
08419519
02507259
08026768
02978712
06579167
01678954
03607507
05718546
05299943
03841507
01063895
09444110
00340633
02144847
00925067
01632861
05436503
04490358
08568794
04232158
09309124
08809187
02928800
02003276
08575668
04241910
01290658
03437011
06011009
01085588
06428691
09983361
09821542
03142508
09609223
06646184
08294152
07659845
02708538
05471432
06535573
09278675
02600341
02862956
09469965
09211544
06912285
07887329
09316571
07844829
05566066
02398303
05603559
02804707
05706505
01065140
06047274
04571167
09263047
03250473
00696123
05529904
04932229
02946055
09320011
09501497
08313244
05799703
06131461
09943131
07832916
05371704
00430899
05742745
07578185
02621594
00750755
04600601
06130808
06279778
07404632
00984814
06126600
00807168
01267069
08781105
05362763
08508602
07931689
02864385
05762159
07335932
05052533
07509385
07849259
08817936
00142388
02483185
03609972
01781022
01037478
05942581
09460816
00945803
01108140(所影响的行数为 111 行)

解决方案 »

  1.   

    select id = right('00000000' + cast(cast(rand(checksum(newid()))*10000000 as int) as varchar),8) from sysobjects a , sysobjects b/*
    id               
    ---------------- 
    05459600
    04262973
    03049340
    04451574
    07786702
    06911267
    09950262
    ...
    (所影响的行数为 11881 行)
    */select id = right('00000000' + cast(cast(rand(checksum(newid()))*10000000 as int) as varchar),8) from sysobjects a , sysobjects b , sysobjects c这个更多,不运行给你了,自己去试
      

  2.   

    create procedure GetCardNum 
    @CardNum char(19) output 
    as 
    begin 
    declare @first char(9),@seed int,@rand float,@result varchar(19) 
    set @first='1010 3576' 
    set @seed=datepart(mm,getdate())*100000+datepart(ss,getdate())*1000+datepart(ms,getdate()) 
    set @rand=rand(@seed) 
    --select @seed,@rand,convert(char(18),@rand) set @rand=@rand*100000000 
    declare @randInt int 
    set @randInt=floor(@rand) 
    declare @i int,@temp int 
    set @i=1 
    set @result='' 
    while(@i <9) 
    begin 
    set @temp=@randInt % 10 
    set @randInt=@randInt/10 
        --select @randInt,@temp 
        if @i%4=0 
    set @result=' '+convert(char(1),@temp)+@result 
    else 
    set @result=convert(char(1),@temp)+@result 
        --select @result 
        set @i=@i+1 
    end 
    --select @randInt,@result 
    set @result=@first+@result 
    set @CardNum=@result 
    end 
    go 
    declare @s varchar(19) 
    exec GetCardNum @s output 
    select @s
    我求出随机数了,但不知道怎么插入.!请大大帮忙说说,谢谢啦,!
      

  3.   

    declare @s varchar(19) 
    exec GetCardNum @s output 
    isnert into cardInfo(cardID,....) select @s,......
      

  4.   

    declare @s varchar(19) 
    exec GetCardNum @s output insert into cardInfo(cardID) select @s --或者需要加'1010 3576'的话insert into cardInfo(cardID) select '1010 3576' + @s 
      

  5.   

    我cardInfo里面有几个字段!
    declare @s varchar(19) 
    exec GetCardNum @s output 
    insert into cardInfo(cardID) select @s 
    这样插入的话报错:不能将值 NULL 插入列 'savingType',表 'ATM.dbo.cardInfo';列不允许有空值。INSERT 失败。
    如果后面接values的话,也报错,!麻烦各位大大啦,这题我都搞晕了,谢谢了!