That's OK. I didn't mean to tell you off. It's just that you'll get a much better response round here if people can see you've had a go yourself.It was my fault...
For question 1, what does 'in the current month' actually mean? Does it mean the from date is in the current month, or the to date, or both, or either? You'll need to clarify that before you can design a query to resolve it. Looking at your query so far it looks like you're basing it on the from date only, which means you'll want something like:-
The syntax might change a bit depending on which database system you're using. The point is you check that the month of the from date is the same as the month of the current date. If you want to base it on both dates in some way then it's going to get more complicated.Code:Select * From Booking Where Month(DateFrom) = Month(GetDate())
For question 2 there's a couple of ways you can do it but I personally like the NOT EXISTS clause because it's the easiest to understand.
Code:Select * From Room Where NOT EXISTS (Select * From Booking Where Booking.RoomID = Room.RoomID And Booking.HotelID = Booking.HotelID And FromDate <= GetDate() And ToDate >= GetDate())
Hope that helps as a starter. Try those queries out and, if they don't give you what you want, let us know what the problem is and we'll be able to help further.




Reply With Quote