CREATE FUNCTION [dbo].[GetNumberOfAvailableSubRooms](@AParentRoomNumber INT, @AArrival DATETIME, @ADeparture DATETIME) 
RETURNS INT
AS
BEGIN
	DECLARE @ResultVar INT

	SELECT @ResultVar = Count(*) FROM Rooms WITH (NOLOCK) 
	WHERE ParentRoomNumber = @AParentRoomNumber
	--AND dbo.IsRoomInhouse(RoomNumber)=0
	AND dbo.GetAvailableMins(RoomNumber,  @AArrival , 1) >= DATEDIFF(MINUTE, @AArrival, @ADeparture)

	RETURN @ResultVar
END

