能否請你幫:隨機化日期SQL
我有一個需要5000行增加了它與隨機日期從2010年度
例如一個抵達的日期列:01/01/2010
,25/8/2010
,03/05/2010
,31/12/2010
等
我認爲這將是一個INSERT
聲明,但我不確定。
感謝
韋恩
USE Occupancy
CREATE TABLE Book
(BookNumber varchar(30),
ArrivalDate int)
DECLARE @BookNumber varchar(30)
DECLARE @ArrivalDate int
SET @BookNumber = 1
SET @ArrivalDate = 0
WHILE @BookNumber <= 5000
WHILE @ArrivalDate <= 5000
BEGIN
INSERT INTO Book (BookNumber,ArrivalDate)
SELECT 'B' + Right ('00000000' + CAST(@BookNumber AS varchar(30)),8),
DATEADD(day, CAST(RAND() * 365 as int), '2010-1-1')
SET @BookNumber = @BookNumber + 1
SET @ArrivalDate = @ArrivalDate + 1
END
[相關](HTTP:// stackoverflow.com/questions/5519486/select-a-random-date-within-specific-range),[也相關](http://stackoverflow.com/questions/794637/how-to-update -rows上帶有一個隨機至今)。 – Dukeling 2013-02-14 15:29:23