select convert(datetime,convert(varchar(2),datepart(hh,checktime1))+':'+convert(varchar(2),datepart(mi,'18:00'))+':'+
convert(char(2),dateadd(ss,cast((rand()*(60-1)+1)   as   int),'18:00'))) 
谁能帮我看看这句中为什么秒那里出不来随机数

解决方案 »

  1.   

    select convert(datetime,convert(varchar(2),datepart(hh,checktime1))+':'+convert(varchar(2),datepart(mi,checktime1))+':'+ 
    convert(char(2),dateadd(ss,cast((rand()*(60-1)+1)  as  int),'18:00'))) 这样就行了!请问楼主的格式是不是DATETIME类型的!
      

  2.   

    select convert(datetime,convert(varchar(2),datepart(hh,checktime1))+':'
          +convert(varchar(2),datepart(mi,checktime1))+':'+ 
            convert(char(2),dateadd(ss,cast((rand()*(60-1)+1)  as  int),checktime1))) 怎么时间有固定18:00的呢?
      

  3.   

    convert(char(2),dateadd(ss,cast((rand()*(60-1)+1)  as  int),'18:00'))) 这里转成CHAR(2)只能是19吧
      

  4.   


    select convert(datetime,convert(varchar(2),datepart(hh,checktime1))+':'+convert(varchar(2),datepart(mi,checktime1))+':'+ 
    convert(char(2),dateadd(ss,cast((rand()*(60-1)+1)  as  int),checktime1))) from fpc_check_deal where rno='7777' and check_date='2009-09-16'原句是这样的
    里面的时间都是datetime格式的
      

  5.   


    select convert(datetime,convert(varchar(2),datepart(hh,checktime1))+':'+convert(varchar(2),datepart(mi,checktime1))+':'+ 
    convert(char(2),dateadd(ss,cast((rand()*(60-1)+1)  as  int),checktime1))) from fpc_check_deal where rno='7777' and check_date='2009-09-16'
      

  6.   


    checktime1
    你最后那里只能是checktime1的年份前两位
      

  7.   

    假设checktime1是'18:00'
    他转换出来的结果就是1900-01-01 18:00:01.000
    秒那里出不来随机数的
      

  8.   

    SELECT dateadd(ss,cast((rand()*(60-1)+1)  as  int),'18:00')
                                                           
    ------------------------------------------------------ 
    1900-01-01 18:00:54.000(所影响的行数为 1 行)
    是毫秒还是秒?/秒那里会有的呀
      

  9.   


    单独拿出来是会有秒的
    我现在是要整句select出来的时间有随机秒出来
      

  10.   

    select convert(datetime,convert(varchar(2),datepart(hh,checktime1))+':'+convert(varchar(2),datepart(mi,checktime1))+':'+
    convert(char(20),datepart(ss,dateadd(ss,cast((rand()*(60-1)+1)   as   int),checktime1)))) 
    from fpc_check_deal where rno='7777' and check_date='2009-09-16'=============================
    1900-01-01 18:00:49.000
      

  11.   

    查询得到多条记录时,用rand()只能得到一个值。
    用newid()吧。
    abs(checksum(newid()))%60
    参考:
    http://topic.csdn.net/u/20090915/14/b598ee17-7c2e-4c6c-b56f-1d7aa00ff5a2.html