
DECLARE @Count INT

SELECT @Count = COUNT(*) 
FROM ArrangementLines WITH (NOLOCK)
  WHERE (ISNULL(PacketItemWareNumber, 0) = 0)
     OR (ISNULL(PacketItemPrice, -1) = -1)
	 OR (ISNULL(PacketItemWareText, '') = '')

IF @Count > 0
BEGIN
  DECLARE @ArrangementLinenumber INT
  DECLARE @PacketItemNumber INT
  DECLARE @PacketItemTextOverwrite VARCHAR(80)
  DECLARE @PacketItemPriceOverwrite money
  DECLARE @PacketItemWareNumber INT

  IF EXISTS (SELECT * FROM dbo.SysObjects WHERE id = object_id(N'dbo.ArrangementLineIllegalWare') AND OBJECTPROPERTY(id, N'IsTrigger') = 1)
    DISABLE TRIGGER ArrangementLineIllegalWare ON dbo.ArrangementLines

  DECLARE TempCursor CURSOR FOR
    SELECT DISTINCT PacketItemNumber 
    FROM ArrangementLines WITH (NOLOCK)
    WHERE (ISNULL(PacketItemWareNumber, 0) = 0)
       OR (ISNULL(PacketItemPrice, -1) = -1)
	   OR (ISNULL(PacketItemWareText, '') = '')
  OPEN TempCursor
  FETCH NEXT FROM TempCursor INTO @PacketItemNumber
  WHILE (@@FETCH_STATUS <> -1)
  BEGIN
    SELECT 
      @PacketItemTextOverwrite = TextOverwrite, 
	  @PacketItemPriceOverwrite = PriceOverwrite, 
	  @PacketItemWareNumber = WareNumber 
    FROM PacketItem_NEW WITH (NOLOCK) 
    WHERE PacketItemNumber = @PacketItemNumber
	 
    UPDATE ArrangementLines
    SET 
      PacketItemPrice = @PacketItemPriceOverwrite,
	  PacketItemWareNumber = @PacketItemWareNumber,
	  PacketItemWareText = @PacketItemTextOverwrite
    WHERE PacketItemNumber = @PacketItemNumber

	UPDATE ArrangementLinesDeleted
    SET 
      PacketItemPrice = @PacketItemPriceOverwrite,
	  PacketItemWareNumber = @PacketItemWareNumber,
	  PacketItemWareText = @PacketItemTextOverwrite
    WHERE PacketItemNumber = @PacketItemNumber

	UPDATE ArrangementLinesDepDeleted
    SET 
      PacketItemPrice = @PacketItemPriceOverwrite,
	  PacketItemWareNumber = @PacketItemWareNumber,
	  PacketItemWareText = @PacketItemTextOverwrite
    WHERE PacketItemNumber = @PacketItemNumber

    FETCH NEXT FROM TempCursor INTO @PacketItemNumber
  END
  CLOSE TempCursor
  DEALLOCATE TempCursor

  IF EXISTS (SELECT * FROM dbo.SysObjects WHERE id = object_id(N'dbo.ArrangementLineIllegalWare') AND OBJECTPROPERTY(id, N'IsTrigger') = 1)
    ENABLE TRIGGER ArrangementLineIllegalWare ON dbo.ArrangementLines

END
