
CREATE PROCEDURE DBO.UpdateMissingPCDepartment_Arrangement @AReferenceNumber INTEGER, @APK_Department INT AS
SET NOCOUNT ON
/*

  20060815 AV: Created

*/

DECLARE
@ArrLineNumber INTEGER

DECLARE #Cursor CURSOR LOCAL FAST_FORWARD FOR

SELECT DISTINCT ArrangementLines.ArrangementLineNumber FROM ArrangementLines WITH (NOLOCK) INNER JOIN ArrangementReservationsXTab WITH (NOLOCK) ON
ArrangementLines.ArrangementLineNumber = ArrangementReservationsXTab.ArrangementLineNumber INNER JOIN ArrangementRoomXTab WITH (NOLOCK) ON ArrangementLines.ArrangementLineNumber=
ArrangementRoomXTab.ArrangementLineNumber
WHERE ArrangementReservationsXTab.ReferenceNumber = @AReferenceNumber AND
ISNULL(ArrangementLines.FK_PacketChargeDepartment,0) = 0

OPEN #Cursor

FETCH NEXT FROM #Cursor
INTO @ArrLineNumber

WHILE (@@FETCH_STATUS <> -1)
BEGIN
  UPDATE ArrangementLines SET FK_PacketChargeDepartment = @APK_Department WHERE ArrangementLineNumber= @ArrLineNumber
  FETCH NEXT FROM #Cursor
  INTO @ArrLineNumber
END

CLOSE #Cursor
DEALLOCATE #Cursor

