Results 1 to 2 of 2

Thread: Problem using SQL count property

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Location
    South Africa
    Posts
    105

    Problem using SQL count property

    Trying to count a NumberOfRooms field in a table where records are between a start and an end date.

    Coming back with an error saying that:

    "Reservation.StartDate invalid because it's not contained in an aggregate function and there is no GROUP BY clause"

    Here is the SQL code - could you tell me what is wrong with it

    strSQL = "SELECT StartDate, EndDate, COUNT(NumOfRooms) AS RoomsOccupied FROM Reservation WHERE StartDate <= '" & strDate & "' AND EndDate >= '" & strDate & "'".

    I have used the code without count and it finds the right records. Problem when I added the count feature.

    Thanks

  2. #2
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Change the query to
    strSQL = "SELECT StartDate, EndDate, COUNT(NumOfRooms) AS RoomsOccupied FROM Reservation WHERE StartDate <= '" & strDate & "' AND EndDate >= '" & strDate & "'" & " Group By StartDate,EndDate".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width