国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

循環插入一定時間范圍內的隨機日期值

2024-07-21 02:42:20
字體:
來源:轉載
供稿:網友
SQL Server中循環插入一定時間范圍內的隨機日期值

-- First, let's declare the date range. I am declaring this     -- here for the demo, but this could be done anyway you like.     DECLARE @date_from DATETIME;     DECLARE @date_to DATETIME;           -- Set the start and date dates. In this case, we are using     -- the month of october, 2006.     SET @date_from = '2006-10-01';     SET @date_to = '2006-10-30';           -- insert  random dates.     insert into randomdate SELECT     (     -- Remember, we want to add a random number to the     -- start date. In SQL we can add days (as integers)     -- to a date to increase the actually date/time     -- object value.     @date_from +     (     -- This will force our random number to be GTE 0.     ABS(           -- This will give us a HUGE random number that     -- might be negative or positive.     CAST(     CAST( NewID() AS BINARY(8) )     AS INT     )     )           -- Our random number might be HUGE. We can't have     -- exceed the date range that we are given.     -- Therefore, we have to take the modulus of the     -- date range difference. This will give us between     -- zero and one less than the date range.     %           -- To get the number of days in the date range, we     -- can simply substrate the start date from the     -- end date. At this point though, we have to cast     -- to INT as SQL will not make any automatic     -- conversions for us.     CAST(     (@date_to - @date_from)     AS INT     )     )     )

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 西平县| 夹江县| 延川县| 邵阳市| 刚察县| 新昌县| 巴彦淖尔市| 怀化市| 阿拉善盟| 和田县| 清水河县| 诸城市| 留坝县| 文登市| 天台县| 金秀| 汉中市| 海晏县| 邵武市| 道孚县| 亚东县| 怀仁县| 古交市| 印江| 女性| 南充市| 比如县| 商都县| 方山县| 阳信县| 将乐县| 车险| 佛坪县| 陆丰市| 乌海市| 清流县| 黔江区| 邹城市| 稻城县| 夏邑县| 宜黄县|