CREATE PROCEDURE [dbo].[GA_AllotmentInsert] @FormatedStartDate CHAR(8), @FormatedEndDate CHAR(8), @SystemDateStr CHAR(8), @TheHotelNumber INT, @NightAuditRunning BIT AS
SET NOCOUNT ON
/*
UPDATE AllotmentLines SET
  CurrentCount = 0
WHERE DateStamp <= @FormatedEndDate AND DateStamp >= @FormatedStartDate  AND DateStamp>=@SystemDateStr AND (CurrentCount <> 0)
AND AllotmentNumber IN (SELECT AllotmentNumber FROM Allotments (NOLOCK) WHERE (@TheHotelNumber=-1 OR HotelNumber = @TheHotelNumber OR (HotelNumber IS NULL AND @TheHotelNumber=0)))

DECLARE
@AllotmentNumber INT,
@RoomTypeNumber INT,
@DateStamp CHAR(8),
@CurrentCount SMALLINT

DECLARE #AllotCur CURSOR FAST_FORWARD FOR

  SELECT * FROM #AllotmentLines (NOLOCK)
  WHERE (DateStamp >= @SystemDateStr OR (@NightAuditRunning > 0)) AND DateStamp >= @FormatedStartDate AND DateStamp <= @FormatedEndDate OPTION (KEEP PLAN)

  OPEN #AllotCur
  FETCH NEXT FROM #AllotCur
  INTO @AllotmentNumber, @RoomTypeNumber, @DateStamp, @CurrentCount

  WHILE  (@@FETCH_STATUS <> -1)
  BEGIN
    IF @CurrentCount > 0
    BEGIN
      UPDATE AllotmentLines SET
        CurrentCount=@CurrentCount
      WHERE AllotmentNumber=@AllotmentNumber AND RoomTypeNumber=@RoomTypeNumber AND DateStamp=@DateStamp
      IF @@rowcount = 0
        INSERT INTO AllotmentLines (AllotmentNumber,RoomTypeNumber,DateStamp,InitialCount,CurrentCount,TotalChange)
        VALUES (@AllotmentNumber, @RoomTypeNumber, @DateStamp, 0, @CurrentCount, 0)
    END
	
    FETCH NEXT FROM #AllotCur
    INTO @AllotmentNumber, @RoomTypeNumber, @DateStamp, @CurrentCount
END

CLOSE #AllotCur
DEALLOCATE #AllotCur

*/





