简体   繁体   中英

Grand Total from DATEDIFF

Another easy one that I haven't got a clue on how to solve and was wondering if you could help. I need to total up 1.4 million rows of data, each row has a amount of PitchNights, Row 1 = 2, Row 2 = 26, Row 14000 = 3 etc, so if i only had these 3 rows the total would be 31. What I need to is have a grand total of all Pitch nights between 2 set dates. I tried the group by function but that didn't work.

SELECT
  Bookings.BookingNumber
  ,Bookings.ArrivalDate
  ,Bookings.DepartureDate, DATEDIFF(d,Bookings.ArrivalDate
  ,Bookings.DepartureDate) AS 'PitchNights'
FROM
  Bookings
WHERE Bookings.ArrivalDate >=@ArrivalDate AND Bookings.DepartureDate <=@DepartureDate

Thanks

Wayne

SELECT  SUM(DATEDIFF(d,Bookings.ArrivalDate,Bookings.DepartureDate)) AS 'PitchNights'
FROM    Bookings
WHERE   Bookings.ArrivalDate >=@ArrivalDate AND 
        Bookings.DepartureDate <=@DepartureDate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM