插入随机增加的日期时间和列表数组

时间:2013-10-21 09:08:10

标签: sql sql-server tsql random dateadd

我有一些gps lat lng点与,其中一些

分开
  28.964783549308777,41.00934982475349,0
  28.964102268218994,41.00941054477526,0
  28.9627343416214,41.00958865651625,0
  28.96224081516266,41.00963318437629,0
  28.961591720581055,41.0096412803476,0

我有大约1K行。 (我可以删除不需要的,0

我的专栏有lat,lng,date,speed。我想用这个lat lng添加它们并随机增加时间和随机速度。

第一个时间的例子是2013-10-21 12:03:20第二个2013-10-21 12:03:23第三个2013-10-21 12:03:25第二个必须随机增加2到5秒。

速度必须在20到35之间随机变化。

如何将所有这些组合并自动插入?

1 个答案:

答案 0 :(得分:0)

DECLARE @StartDate datetime = GETDATE()

;with dt as (
SELECT CAST(1 as int) as ID, @StartDate as dtime,CAST(20+ROUND(15*RAND(CHECKSUM(NEWID())),0) as int) as speed
UNION ALL
SELECT ID + 1, DATEADD(SECOND,2+ROUND(3*RAND(CHECKSUM(NEWID())),0),dtime) , CAST(20+ROUND(15*RAND(CHECKSUM(NEWID())),0) as int)
FROM dt
WHERE ID <= 1000)

SELECT *
FROM dt
OPTION (MAXRECURSION 0);
GO