CREATE PROCEDURE DBO.IsHallAvailable @Arrivaldate char(8),@ArrivalTime char(5),@DepartureDate char(8),@DepartureTime char(5),@HallNumber int, @LineNumber int, @CheckForOutForService int = 0, @Result int output AS
/*
    JP 20040415 out-for-service
*/
SET NOCOUNT ON

declare @rowcount int
--   SELECT ReservationConferenceline.ReservationConflinenumber FROM ReservationConferenceline (Nolock) INNER JOIN RESERVATIONS (NOLOCK) ON RESERVATIONCONFERENCELINE.ReferenceNumber = RESERVATIONS.ReferenceNumber
   SELECT @rowcount=count (*) FROM ReservationConferenceline WITH (Nolock) INNER JOIN RESERVATIONS WITH (NOLOCK) ON RESERVATIONCONFERENCELINE.ReferenceNumber = RESERVATIONS.ReferenceNumber
   INNER JOIN CONFERENCEROOMSXTAB WITH (Nolock) ON ConferenceRoomsxtab.ConferenceRoomNumber = ReservationConferenceLine.ConferenceRoomNumber 
--    WHERE GuestNumber = 0
   WHERE (((@CheckForOutForService=0) AND (ReservationConferenceline.ReferenceNumber <>-2)) OR ((@CheckForOutForService=1) AND (ReservationConferenceline.ReferenceNumber=-2))) -- JP 20040415
   AND GuestNumber = 0

   AND ReservationconfLineNumber<>@LineNumber

   AND ISNULL(SchemePattern, 0) = 0

   AND (LinkLineNumber<>@LineNumber or (LinkLineNumber is null and ReservationconfLineNumber<>@LineNumber))

   AND CONFERENCEROOMSXTAB.CollectsConferenceRoomNumber=@HallNumber
   AND Status <>7
   AND Status <> 8

   AND ((ReservationConferenceline.ArrivalDate<@DepartureDate AND ReservationConferenceline.DepartureDate>@ArrivalDate)
   OR (ReservationConferenceline.ArrivalDate=@DepartureDate AND ReservationConferenceline.ArrivalTime<@DepartureTime AND ReservationConferenceline.departureTime>@ArrivalTime)
   OR (ReservationConferenceline.DepartureDate=@ArrivalDate  AND ReservationConferenceline.DepartureTime>@Arrivaltime AND ReservationConferenceline.ArrivalTime<@Departuretime)
   OR (ReservationConferenceline.DepartureDate>@ArrivalDate AND ReservationConferenceline.arrivalDate=@Departuredate and ReservationConferenceline.arrivaltime<@Departuretime)
   OR (ReservationConferenceline.ArrivalDate<@Departuredate AND ReservationConferenceline.DepartureDate=@Arrivaldate and ReservationConferenceline.Departuretime>@Arrivaltime))

--if @@rowcount > 0 	
if @rowcount > 0
begin
      set @result =0
--print 'rowcount er større end 0'
end
  else
begin
      set @result = 1     
--print 'rowcount = 0'
end

