create table test(tt varchar(5))insert into test
select '08:00'
union all
select '08:00'
union all
select '08:00'
union all
select '08:00'
现在要实现的是
tt aa (效果)
08:00 08:01
08:00 08:02
08:00 08:10
08:00 08:22要求就是后列要随机生成的。以前我是用游标,但速度不够快。
select '08:00'
union all
select '08:00'
union all
select '08:00'
union all
select '08:00'
现在要实现的是
tt aa (效果)
08:00 08:01
08:00 08:02
08:00 08:10
08:00 08:22要求就是后列要随机生成的。以前我是用游标,但速度不够快。
select '08:00'
union all
select '08:00'
union all
select '08:00'
union all
select '08:00'
GO
Select
tt,
'08:' + Right(100 + Cast(Rand(CheckSUM(NewID())) * 59 As Int), 2) As aa
From
test
GO
Drop Table test
--Result
/*
tt aa
08:00 08:21
08:00 08:36
08:00 08:38
08:00 08:20
*/
select '08:00'
union all
select '08:00'
union all
select '08:00'
union all
select '08:00'
GOSelect
tt,
Convert(Varchar(5), DateAdd(mi, Cast(Rand(CheckSUM(NewID())) * 59 As Int), '1900-01-01 ' + tt), 108) As aa
From
test
GO
Drop Table test
--Result
/*
tt aa
08:00 08:21
08:00 08:38
08:00 08:27
08:00 08:30*/
可以重复,但要随机的。
------
那就OK。看你的實際情況,取我寫的兩種情況中的一種吧。
select '08:00'
union all
select '08:00'
union all
select '08:00'
union all
select '08:00'
GO
Select
tt,
Left(tt, 3) + Right(100 + Cast(Rand(CheckSUM(NewID())) * 59 As Int), 2) As aa
From
test
GO
Drop Table test
--Result
/*
tt aa
08:00 08:32
08:00 08:05
08:00 08:21
08:00 08:26
*/
insert into @t
select '08:00'
union all
select '08:00'
union all
select '08:00'
union all
select '08:00'
select t,left(t,3)+replace(str(right(checksum(newid()),2)%60,2),' ','0') aa from @t
select '08:00'
union all
select '08:00'
union all
select '08:00'
union all
select '08:00'
GO
--建立函數
Create Function F_TEST(@tt varchar(5), @NewID Float)
Returns Varchar(5)
As
Begin
Return Left(@tt, 3) + Right(100 + Cast(@NewID * 59 As Int), 2)
End
GO
--調用
Select
tt,
dbo.F_TEST(tt, Rand(CheckSUM(NewID()))) As aa
From
test
GO
Drop Table test
Drop Function F_TEST
--Result
/*
tt aa
08:00 08:55
08:00 08:25
08:00 08:20
08:00 08:05
*/