国产探花免费观看_亚洲丰满少妇自慰呻吟_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     )     )     )

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宁强县| 上蔡县| 高密市| 布尔津县| 沭阳县| 鄯善县| 如东县| 昭通市| 循化| 丰顺县| 罗江县| 阜平县| 伊金霍洛旗| 广丰县| 巴林左旗| 阳朔县| 绥宁县| 华安县| 大宁县| 高要市| 托里县| 荥阳市| 额尔古纳市| 乡城县| 唐海县| 太保市| 晋江市| 达孜县| 孝感市| 广东省| 贵州省| 沁阳市| 黔江区| 宁海县| 伊吾县| 体育| 镇宁| 建德市| 泌阳县| 安仁县| 海原县|