SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Populating a Booking date usind dateadd
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

wafw1971
Yak Posting Veteran

75 Posts

Posted - 02/20/2013 :  07:16:40  Show Profile  Reply with Quote
I have an arrival date already in the system and I need to populate the Booking date using a random function, the booking date can be any day on or before the arrival date up to a maximum 90 days previous but it must be random the booking date cannot all be the same date.

I thought I cracked it but was wrong. Can you help?

SELECT ArrivalDate, DATEADD(day, -1 + RAND(checksum(NEWID()))-90
, ArrivalDate) AS BookingDate
FROM Bookings
ORDER BY ArrivalDate

Thanks

Wayne

wafw1971
Yak Posting Veteran

75 Posts

Posted - 02/20/2013 :  07:31:23  Show Profile  Reply with Quote
Its alright I have figured it out:

SELECT ArrivalDate, DATEADD(day, -1 + RAND(checksum(NEWID()))*-90
, ArrivalDate) AS BookingDate
FROM Bookings
ORDER BY ArrivalDate
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000