Results 1 to 6 of 6
  1. #1
    John Elway is offline Novice
    Windows Vista Access 2007
    Join Date
    Nov 2011
    Posts
    3

    query question

    Hi everyone.....

    I have following SQL code.

    Code:
    SELECT Reservations.[Room Type], Avg(DateDiff("d",[Arrival Date],[Departure Date])) AS [Avg Length of Stay], Avg(Reservations.[No of Guests]) AS [Avg # of Visitors], Avg(Reservations.[Daily Rate]) AS [Daily Rate]
    FROM Reservations
    GROUP BY Reservations.[Room Type]
    ORDER BY Reservations.[Room Type];
    and

    Code:
    SELECT Avg_Length_of_Stay.[Room Type], Format(Avg([Daily Rate]*[Avg Length of Stay]),"Currency") AS AvgBill
    FROM Avg_Length_of_Stay LEFT JOIN Reservations ON Avg_Length_of_Stay.[Room Type] = Reservations.[Room Type]
    GROUP BY Avg_Length_of_Stay.[Room Type];
    Now here is the dilemma. This code is for 1-4 guests per night. But if there is a fifth and sixth guest, they must pay an additional $20 EACH per day. How would I alter the code to make up for this point.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    This will add $20 per guest in excess of 4.
    Avg(Reservations.[Daily Rate] + IIf([No of Guests] > 4, ([No of Guests] - 4) * 20, 0)) AS [Daily Rate]
    Last edited by June7; 11-09-2011 at 08:39 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    John Elway is offline Novice
    Windows Vista Access 2007
    Join Date
    Nov 2011
    Posts
    3
    I can not tell from the code but does this account the surge PER DAY. I can see you have added an if state which takes into consideration the $20 surcharge but is that for EACH day or a one time surcharge? I am looking for the $20 surcharge applied each day. So IE, if the there are 6 people to the room and they stay for 3 days, then it would be 2ppl*20 = 40, then 40 multiplied by 3 days = $120.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    That is adjusting the daily rate. Need to multiply by total nights. I was merely adjusting the Avg calc in the first query, which is averaging over total records, not total guests or total days. Adjust the calcs in other query in the same way.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    John Elway is offline Novice
    Windows Vista Access 2007
    Join Date
    Nov 2011
    Posts
    3
    Where in the first queiry should I put your Avg(Reservations.[Daily Rate] + IIf([No of Guests] > 4, ([No of Guests] - 4) * 20, 0)) AS [Daily Rate] calculation?
    Sorry this is over my head.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    In place of the last calc: Avg(Reservations.[Daily Rate]) AS [Daily Rate]

    Unless you don't want to adjust the daily rate in that query.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query question/help
    By 9944pdx in forum Queries
    Replies: 4
    Last Post: 12-12-2017, 08:13 PM
  2. vba query question
    By jscriptor09 in forum Programming
    Replies: 2
    Last Post: 10-08-2011, 07:22 PM
  3. Query Question
    By CarlV in forum Access
    Replies: 2
    Last Post: 09-20-2011, 06:25 AM
  4. Query question
    By j2curtis64 in forum Queries
    Replies: 8
    Last Post: 07-29-2011, 01:45 PM
  5. Query Question
    By starhannes in forum Queries
    Replies: 13
    Last Post: 05-06-2010, 04:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums