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')))
谁能帮我看看这句中为什么秒那里出不来随机数
convert(char(2),dateadd(ss,cast((rand()*(60-1)+1) as int),'18:00')))
谁能帮我看看这句中为什么秒那里出不来随机数
convert(char(2),dateadd(ss,cast((rand()*(60-1)+1) as int),'18:00'))) 这样就行了!请问楼主的格式是不是DATETIME类型的!
+convert(varchar(2),datepart(mi,checktime1))+':'+
convert(char(2),dateadd(ss,cast((rand()*(60-1)+1) as int),checktime1))) 怎么时间有固定18:00的呢?
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格式的
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'
checktime1
你最后那里只能是checktime1的年份前两位
他转换出来的结果就是1900-01-01 18:00:01.000
秒那里出不来随机数的
------------------------------------------------------
1900-01-01 18:00:54.000(所影响的行数为 1 行)
是毫秒还是秒?/秒那里会有的呀
单独拿出来是会有秒的
我现在是要整句select出来的时间有随机秒出来
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
用newid()吧。
abs(checksum(newid()))%60
参考:
http://topic.csdn.net/u/20090915/14/b598ee17-7c2e-4c6c-b56f-1d7aa00ff5a2.html