0

我有一个查询,它会在到达日期字段后 1 到 28 天产生随机出发日期:

--Query--

SELECT ArrivalDate, DATEADD(day, 1 + RAND(checksum(NEWID()))
* LengthOfStay.LengthofStay, ArrivalDate) AS DepartureDate    
FROM Bookings, LengthOfStay

但是,当我运行更新查询时,随机时间减少到 1 或 2 天,谁能告诉我这是为什么?

--Update Statement--

USE Occupancy
Update B
Set DepartureDate = DATEADD(day, 1 + RAND(checksum(NEWID()))*1.5 * L.LengthofStay, B.ArrivalDate)
FROM LengthOfStay L, Bookings B

谢谢

韦恩

4

1 回答 1

0

我使用了以下解决方案:

UPDATE BOOKINGS 
SET DepartureDate = 
DATEADD(day, 
CASE WHEN Rand(CHECKSUM(NEWID())) BETWEEN 0 and 0.3 THEN 2 ELSE 
CASE WHEN Rand(CHECKSUM(NEWID())) BETWEEN 0.3 and 0.5 THEN 3 ELSE 
Round(Rand(CHECKSUM(NEWID())) * 28,0) END END,ArrivalDate) 
于 2013-02-21T10:08:23.493 回答