CREATE FUNCTION DBO.IsOnlyTableReservation (@AReferenceNumber INT)  
/*
  Created by Kent Johansen
  Changes:
    KJ 20080606: Bug Fix for "@@Cursor rows not set when using READ_ONLY"
    KJ 20080317: Bug Fix for "@@Cursor rows not set when using FAST_FORWARD"

*/
RETURNS BIT AS  
BEGIN 
  DECLARE @Result BIT
  SET @Result = 0

  DECLARE db_cur CURSOR /*FAST_FORWARD READ_ONLY*/ FOR
    SELECT LineNumber FROM ReservationRoomLineXtab WITH (NOLOCK) WHERE ReferenceNumber = @AReferenceNumber
    UNION SELECT ReservationConfLineNumber AS LineNumber FROM ReservationConferenceLine WITH (NOLOCK)
    WHERE ReferenceNumber = @AReferenceNumber AND ISNULL(TableBooking,0) = 0
  OPEN db_cur

  IF ISNULL(@@CURSOR_ROWS,0) <= 0
    SET @Result = 1
  ELSE
    SET @Result = 0

  CLOSE db_cur
  DEALLOCATE db_cur

  RETURN @Result
END