CREATE PROCEDURE DBO.CopyProduct @OldProductNumber int, @NewProductNumber int, @NewProductName VarChar (50), @NewDescription VarChar (50)  AS
SET NOCOUNT ON
/*
  Last Changed:
  KJ 20141219: Ext: Changed datatype for prices. Handle amount > 214.000.
  RN 20140910: Bug: Added missing ProductHotelXTAB copying
  2008 1208  AV BUG: product start date must be systemdate if it was smaller than this one
  20060307 JP BUG: fixed productprice not using an index and copied too much data. fixed indexes on xtabs
  20060307 JP Added missing fields to Products, copy only future prices and not past.
  20050502 JP money to smallmoney and deleted productpricenumber
--  Sidst rettet 231002 AV - varchar til moeny
-- Sidst rettet af JP 26-11-2002

*/
--- Product ---
DECLARE
@ProductNumber INT,
@MarkAsDeleted BIT,
@ProductName VarChar (50),
@Description VarChar (50),
@ProductDate Char (8),
@ProductEndDate Char (8),
@DayProduct Bit,
@FixedPrice Bit,
@PriceOverwrite Bit,
@PensionTypeNumber Int,
@BillTypeNumber Int,
@ChangeOfBedSheets Int,
@ProductTypeNumber Int,
@ProductSubtypeNumber Int,
@CancellationFee Real,
@EnvironmentFee Real,
@EnvironmentFeeType SmallInt,
@CurrencyNumber Int,
@MinimumDays Int,
@MaximumDays Int,
@ArrivalMonday Bit,
@ArrivalTuesday Bit,
@ArrivalWednesday Bit,
@ArrivalThursday Bit,
@ArrivalFriday Bit,
@ArrivalSaturday Bit,
@ArrivalSunday Bit,
@NameListSetting TINYINT,
@AllowFilterAvailability BIT,
@AllowFilterPicassoOnline BIT,
@AllowFilterCustomerNumber BIT,
@AllowFilterCustomerGroup BIT,
@AllowFilterOtherBookSystem BIT,
@UseMinMaxDaysOnlyOnline BIT,
@MatchDayColor INT,
@OwnerSettlement BIT,

@BillTextProduct VarChar (50),
@BillTextArrival VarChar (50),
@BillTextStay VarChar (50),
@BillTextDeparture VarChar (50),
@ExcludeVAT bit,
@AddonType smallint,
@SystemDateStr CHAR(8)

SELECT @SystemDateStr = SystemDate FROM System WITH (NOLOCK) WHERE Number=1

SELECT @MarkAsDeleted=MarkAsDeleted, @ProductName=ProductName, @Description=Description, @ProductDate=ProductDate, @ProductEndDate=ProductEndDate, @DayProduct=DayProduct, @FixedPrice=FixedPrice,
@PriceOverwrite=PriceOverwrite, @PensionTypeNumber=PensionTypeNumber, @BillTypeNumber=BillTypeNumber, @ChangeOfBedSheets=ChangeOfBedSheets, @ProductTypeNumber=ProductTypeNumber, @ProductSubTypeNumber=ProductSubtypeNumber,
@CancellationFee=CancellationFee, @EnvironmentFee=EnvironmentFee, @EnvironmentFeeType=EnvironmentFeeType, /*@CurrencyNumber=CurrencyNumber,*/ @MinimumDays=MinimumDays, @MaximumDays=MaximumDays, @ArrivalMonday=ArrivalMonday, @ArrivalTuesDay=ArrivalTuesday, @ArrivalWednesDay=ArrivalWednesDay,
@ArrivalThursday=ArrivalThursday, @ArrivalFriday=ArrivalFriday, @ArrivalSaturday=ArrivalSaturday, @ArrivalSunday=ArrivalSunday, 
@BillTextProduct=BillTextProduct, @BillTextArrival=BillTextArrival, @BillTextStay=BillTextStay, @BillTextDeparture=BillTextDeparture, @ExcludeVAT=ExcludeVAT,@AddonType=AddonType, @NameListSetting=NameListSetting,
@AllowFilterAvailability=AllowFilterAvailability, @AllowFilterPicassoOnline=AllowFilterPicassoOnline, @AllowFilterCustomerNumber=AllowFilterCustomerNumber, @AllowFilterCustomerGroup=AllowFilterCustomerGroup, @AllowFilterOtherBookSystem=AllowFilterOtherBookSystem, 
@UseMinMaxDaysOnlyOnline=UseMinMaxDaysOnlyOnline, @MatchDayColor=MatchDayColor, @OwnerSettlement=OwnerSettlement
FROM Products WITH (NOLOCK)
WHERE ProductNumber = @OldProductNumber
IF @@rowcount = 0
  RETURN

IF @ProductDate < @SystemDateStr
  SET @ProductDate = @SystemDateStr

INSERT INTO Products (ProductNumber, MarkAsDeleted, ProductName, Description, ProductDate, ProductEndDate, DayProduct, FixedPrice,
  PriceOverwrite, PensionTypeNumber, BillTypeNumber, ChangeOfBedSheets, ProductTypeNumber, ProductSubtypeNumber,
  CancellationFee, EnvironmentFee, EnvironmentFeeType, /*CurrencyNumber,*/ MinimumDays, MaximumDays, ArrivalMonday, ArrivalTuesday, ArrivalWednesday,
  ArrivalThursday, ArrivalFriday, ArrivalSaturday, ArrivalSunday, 
  BillTextProduct, BillTextArrival, BillTextStay, BillTextDeparture, ExcludeVAT,AddonType, NameListSetting,
  AllowFilterAvailability, AllowFilterPicassoOnline, AllowFilterCustomerNumber, AllowFilterCustomerGroup, AllowFilterOtherBookSystem, UseMinMaxDaysOnlyOnline, MatchDayColor, OwnerSettlement)
VALUES (@NewProductNumber, @MarkAsDeleted, @NewProductName, @NewDescription, @ProductDate, @ProductEndDate, @DayProduct, @FixedPrice,
  @PriceOverwrite, @PensionTypeNumber, @BillTypeNumber, @ChangeOfBedSheets, @ProductTypeNumber, @ProductSubtypeNumber,
  @CancellationFee, @EnvironmentFee, @EnvironmentFeeType, /*@CurrencyNumber,*/ @MinimumDays, @MaximumDays, @ArrivalMonday, @ArrivalTuesday, @ArrivalWednesday,
  @ArrivalThursday, @ArrivalFriday, @ArrivalSaturday, @ArrivalSunday, 
  @BillTextProduct, @BillTextArrival, @BillTextStay, @BillTextDeparture, @ExcludeVAT,@AddonType, @NameListSetting,
  @AllowFilterAvailability, @AllowFilterPicassoOnline, @AllowFilterCustomerNumber, @AllowFilterCustomerGroup, @AllowFilterOtherBookSystem, @UseMinMaxDaysOnlyOnline, @MatchDayColor, @OwnerSettlement)

/*
  Fetch Next From CopyCur
  Into @ProductNumber, @MarkAsDeleted, @ProductName, @Description, @ProductDate, @ProductEndDate, @DayProduct, @FixedPrice,
  @PriceOverwrite, @PensionTypeNumber, @BillTypeNumber, @ChangeOfBedSheets, @ProductTypeNumber, @ProductSubtypeNumber,
  @CancellationFee, @EnvironmentFee, @EnvironmentFeeType, @CurrencyNumber, @MinimumDays, @MaximumDays, @ArrivalMonday, @ArrivalTuesday, @ArrivalWendesday,
  @ArrivalThursday, @ArrivalFriday, @ArrivalSaturday, @ArrivalSunday, 
  @BillTextProduct, @BillTextArrival, @BillTextStay, @BillTextDeparture, @ExcludeVAT, @AddonType, @NameListSetting
END

CLOSE CopyCur
DEALLOCATE CopyCur
*/

--- ProductPrice ---

-- Declare all fields in ProductPrice
--Declare @ProductNumber Int  Already declared 
DECLARE
--@SystemDateStr CHAR(8), -- moved up
@DateStamp CHAR (8),
@RoomtypeNumber INT

Declare @AdultPrice1 money
Declare @AdultPrice2 money
Declare @AdultPrice3 money
Declare @AdultPrice4 money
Declare @AdultPrice5 money
Declare @AdultPrice6 money
Declare @AdultPrice7 money
Declare @AdultPrice8 money
Declare @AdultPrice9 money
Declare @Children1Price1 money
Declare @Children1Price2 money
Declare @Children1Price3 money
Declare @Children1Price4 money
Declare @Children1Price5 money
Declare @Children1Price6 money
Declare @Children1Price7 money
Declare @Children1Price8 money
Declare @Children1Price9 money
Declare @Children2Price1 money
Declare @Children2Price2 money
Declare @Children2Price3 money
Declare @Children2Price4 money
Declare @Children2Price5 money
Declare @Children2Price6 money
Declare @Children2Price7 money
Declare @Children2Price8 money
Declare @Children2Price9 money
Declare @AdultArrivalAddon smallmoney
Declare @AdultStayAddon smallmoney
Declare @AdultDepartureAddon smallmoney
Declare @Children1ArrivalAddon smallmoney
Declare @Children1StayAddon smallmoney
Declare @Children1DepartureAddon smallmoney
Declare @Children2ArrivalAddon smallmoney
Declare @Children2StayAddon smallmoney
Declare @Children2DepartureAddon smallmoney
Declare @AdultArrivalAddon2 smallmoney
Declare @AdultStayAddon2 smallmoney
Declare @AdultDepartureAddon2 smallmoney
Declare @Children1ArrivalAddon2 smallmoney
Declare @Children1StayAddon2 smallmoney
Declare @Children1DepartureAddon2 smallmoney
Declare @Children2ArrivalAddon2 smallmoney
Declare @Children2StayAddon2 smallmoney
Declare @Children2DepartureAddon2 smallmoney
Declare @AdultArrivalAddon3 smallmoney
Declare @AdultStayAddon3 smallmoney
Declare @AdultDepartureAddon3 smallmoney
Declare @Children1ArrivalAddon3 smallmoney
Declare @Children1StayAddon3 smallmoney
Declare @Children1DepartureAddon3 smallmoney
Declare @Children2ArrivalAddon3 smallmoney
Declare @Children2StayAddon3 smallmoney
Declare @Children2DepartureAddon3 smallmoney
Declare @AdultArrivalAddon4 smallmoney
Declare @AdultStayAddon4 smallmoney
Declare @AdultDepartureAddon4 smallmoney
Declare @Children1ArrivalAddon4 smallmoney
Declare @Children1StayAddon4 smallmoney
Declare @Children1DepartureAddon4 smallmoney
Declare @Children2ArrivalAddon4 smallmoney
Declare @Children2StayAddon4 smallmoney
Declare @Children2DepartureAddon4 smallmoney
Declare @AdultArrivalAddon5 smallmoney
Declare @AdultStayAddon5 smallmoney
Declare @AdultDepartureAddon5 smallmoney
Declare @Children1ArrivalAddon5 smallmoney
Declare @Children1StayAddon5 smallmoney
Declare @Children1DepartureAddon5 smallmoney
Declare @Children2ArrivalAddon5 smallmoney
Declare @Children2StayAddon5 smallmoney
Declare @Children2DepartureAddon5 smallmoney
Declare @AdultArrivalAddon6 smallmoney
Declare @AdultStayAddon6 smallmoney
Declare @AdultDepartureAddon6 smallmoney
Declare @Children1ArrivalAddon6 smallmoney
Declare @Children1StayAddon6 smallmoney
Declare @Children1DepartureAddon6 smallmoney
Declare @Children2ArrivalAddon6 smallmoney
Declare @Children2StayAddon6 smallmoney
Declare @Children2DepartureAddon6 smallmoney
Declare @AdultArrivalAddon7 smallmoney
Declare @AdultStayAddon7 smallmoney
Declare @AdultDepartureAddon7 smallmoney
Declare @Children1ArrivalAddon7 smallmoney
Declare @Children1StayAddon7 smallmoney
Declare @Children1DepartureAddon7 smallmoney
Declare @Children2ArrivalAddon7 smallmoney
Declare @Children2StayAddon7 smallmoney
Declare @Children2DepartureAddon7 smallmoney
Declare @AdultArrivalAddon8 smallmoney
Declare @AdultStayAddon8 smallmoney
Declare @AdultDepartureAddon8 smallmoney
Declare @Children1ArrivalAddon8 smallmoney
Declare @Children1StayAddon8 smallmoney
Declare @Children1DepartureAddon8 smallmoney
Declare @Children2ArrivalAddon8 smallmoney
Declare @Children2StayAddon8 smallmoney
Declare @Children2DepartureAddon8 smallmoney
Declare @AdultArrivalAddon9 smallmoney
Declare @AdultStayAddon9 smallmoney
Declare @AdultDepartureAddon9 smallmoney
Declare @Children1ArrivalAddon9 smallmoney
Declare @Children1StayAddon9 smallmoney
Declare @Children1DepartureAddon9 smallmoney
Declare @Children2ArrivalAddon9 smallmoney
Declare @Children2StayAddon9 smallmoney
Declare @Children2DepartureAddon9 smallmoney

Declare @ArrivalPacketNumber int
Declare @StayPacketNumber int
Declare @DeparturePacketNumber int

--SELECT @SystemDateStr = SystemDate FROM System(NOLOCK) WHERE Number=1 -- moved up

DECLARE CopyCur CURSOR FORWARD_ONLY FOR

SELECT ProductNumber, DateStamp, RoomtypeNumber,
AdultPrice1, AdultPrice2, AdultPrice3, AdultPrice4, AdultPrice5, AdultPrice6, AdultPrice7, AdultPrice8, AdultPrice9,
Children1Price1, Children1Price2, Children1Price3, Children1Price4, Children1Price5, Children1Price6, Children1Price7, Children1Price8, Children1Price9,
Children2Price1, Children2Price2, Children2Price3, Children2Price4, Children2Price5, Children2Price6, Children2Price7, Children2Price8, Children2Price9,
AdultArrivalAddon, AdultStayAddon, AdultDepartureAddon,Children1ArrivalAddon,Children1StayAddon, Children1DepartureAddon,Children2ArrivalAddon,Children2StayAddon, Children2DepartureAddon,
AdultArrivalAddon2, AdultStayAddon2, AdultDepartureAddon2, Children1ArrivalAddon2, Children1StayAddon2, Children1DepartureAddon2, Children2ArrivalAddon2, Children2StayAddon2, Children2DepartureAddon2,
AdultArrivalAddon3, AdultStayAddon3, AdultDepartureAddon3, Children1ArrivalAddon3, Children1StayAddon3, Children1DepartureAddon3, Children2ArrivalAddon3, Children2StayAddon3, Children2DepartureAddon3,
AdultArrivalAddon4, AdultStayAddon4, AdultDepartureAddon4, Children1ArrivalAddon4, Children1StayAddon4, Children1DepartureAddon4, Children2ArrivalAddon4, Children2StayAddon4, Children2DepartureAddon4,
AdultArrivalAddon5, AdultStayAddon5, AdultDepartureAddon5, Children1ArrivalAddon5, Children1StayAddon5, Children1DepartureAddon5, Children2ArrivalAddon5, Children2StayAddon5, Children2DepartureAddon5,
AdultArrivalAddon6, AdultStayAddon6, AdultDepartureAddon6, Children1ArrivalAddon6, Children1StayAddon6, Children1DepartureAddon6, Children2ArrivalAddon6, Children2StayAddon6, Children2DepartureAddon6,
AdultArrivalAddon7, AdultStayAddon7, AdultDepartureAddon7, Children1ArrivalAddon7, Children1StayAddon7, Children1DepartureAddon7, Children2ArrivalAddon7, Children2StayAddon7, Children2DepartureAddon7,
AdultArrivalAddon8, AdultStayAddon8, AdultDepartureAddon8, Children1ArrivalAddon8, Children1StayAddon8, Children1DepartureAddon8, Children2ArrivalAddon8, Children2StayAddon8, Children2DepartureAddon8,
AdultArrivalAddon9, AdultStayAddon9, AdultDepartureAddon9, Children1ArrivalAddon9, Children1StayAddon9, Children1DepartureAddon9, Children2ArrivalAddon9, Children2StayAddon9, Children2DepartureAddon9,
ArrivalPacketNumber,StayPacketNumber, DeparturePacketNumber
FROM ProductPrice WITH (NOLOCK)
WHERE ProductNumber = @OldProductNumber AND DateStamp >= @SystemDateStr AND RoomTypeNumber >= 0 -- make sure we use our primary index

Open CopyCur
Fetch Next From CopyCur
Into @ProductNumber, @DateStamp, @RoomtypeNumber,
@AdultPrice1, @AdultPrice2, @AdultPrice3, @AdultPrice4, @AdultPrice5, @AdultPrice6, @AdultPrice7, @AdultPrice8, @AdultPrice9,
@Children1Price1, @Children1Price2, @Children1Price3, @Children1Price4, @Children1Price5, @Children1Price6, @Children1Price7, @Children1Price8, @Children1Price9,
@Children2Price1, @Children2Price2, @Children2Price3, @Children2Price4, @Children2Price5, @Children2Price6, @Children2Price7, @Children2Price8, @Children2Price9,
@AdultArrivalAddon, @AdultStayAddon, @AdultDepartureAddon,@Children1ArrivalAddon,@Children1StayAddon, @Children1DepartureAddon,@Children2ArrivalAddon,@Children2StayAddon, @Children2DepartureAddon,
@AdultArrivalAddon2, @AdultStayAddon2, @AdultDepartureAddon2, @Children1ArrivalAddon2, @Children1StayAddon2, @Children1DepartureAddon2, @Children2ArrivalAddon2, @Children2StayAddon2, @Children2DepartureAddon2,
@AdultArrivalAddon3, @AdultStayAddon3, @AdultDepartureAddon3, @Children1ArrivalAddon3, @Children1StayAddon3, @Children1DepartureAddon3, @Children2ArrivalAddon3, @Children2StayAddon3, @Children2DepartureAddon3,
@AdultArrivalAddon4, @AdultStayAddon4, @AdultDepartureAddon4, @Children1ArrivalAddon4, @Children1StayAddon4, @Children1DepartureAddon4, @Children2ArrivalAddon4, @Children2StayAddon4, @Children2DepartureAddon4,
@AdultArrivalAddon5, @AdultStayAddon5, @AdultDepartureAddon5, @Children1ArrivalAddon5, @Children1StayAddon5, @Children1DepartureAddon5, @Children2ArrivalAddon5, @Children2StayAddon5, @Children2DepartureAddon5,
@AdultArrivalAddon6, @AdultStayAddon6, @AdultDepartureAddon6, @Children1ArrivalAddon6, @Children1StayAddon6, @Children1DepartureAddon6, @Children2ArrivalAddon6, @Children2StayAddon6, @Children2DepartureAddon6,
@AdultArrivalAddon7, @AdultStayAddon7, @AdultDepartureAddon7, @Children1ArrivalAddon7, @Children1StayAddon7, @Children1DepartureAddon7, @Children2ArrivalAddon7, @Children2StayAddon7, @Children2DepartureAddon7,

@AdultArrivalAddon8, @AdultStayAddon8, @AdultDepartureAddon8, @Children1ArrivalAddon8, @Children1StayAddon8, @Children1DepartureAddon8, @Children2ArrivalAddon8, @Children2StayAddon8, @Children2DepartureAddon8,
@AdultArrivalAddon9, @AdultStayAddon9, @AdultDepartureAddon9, @Children1ArrivalAddon9, @Children1StayAddon9, @Children1DepartureAddon9, @Children2ArrivalAddon9, @Children2StayAddon9, @Children2DepartureAddon9,
@ArrivalPacketNumber,@StayPacketNumber, @DeparturePacketNumber
While (@@Fetch_status=0)
Begin
  Insert Into ProductPrice
  (ProductNumber, DateStamp, RoomtypeNumber, AdultPrice1, AdultPrice2, AdultPrice3, AdultPrice4, AdultPrice5, AdultPrice6, AdultPrice7, AdultPrice8, AdultPrice9,
  Children1Price1, Children1Price2, Children1Price3, Children1Price4, Children1Price5, Children1Price6, Children1Price7, Children1Price8, Children1Price9,
  Children2Price1, Children2Price2, Children2Price3, Children2Price4, Children2Price5, Children2Price6, Children2Price7, Children2Price8, Children2Price9,
  AdultArrivalAddon, AdultStayAddon, AdultDepartureAddon,Children1ArrivalAddon,Children1StayAddon, Children1DepartureAddon,Children2ArrivalAddon,Children2StayAddon, Children2DepartureAddon,
  AdultArrivalAddon2, AdultStayAddon2, AdultDepartureAddon2, Children1ArrivalAddon2, Children1StayAddon2, Children1DepartureAddon2, Children2ArrivalAddon2, Children2StayAddon2, Children2DepartureAddon2,
  AdultArrivalAddon3, AdultStayAddon3, AdultDepartureAddon3, Children1ArrivalAddon3, Children1StayAddon3, Children1DepartureAddon3, Children2ArrivalAddon3, Children2StayAddon3, Children2DepartureAddon3,
  AdultArrivalAddon4, AdultStayAddon4, AdultDepartureAddon4, Children1ArrivalAddon4, Children1StayAddon4, Children1DepartureAddon4, Children2ArrivalAddon4, Children2StayAddon4, Children2DepartureAddon4,
  AdultArrivalAddon5, AdultStayAddon5, AdultDepartureAddon5, Children1ArrivalAddon5, Children1StayAddon5, Children1DepartureAddon5, Children2ArrivalAddon5, Children2StayAddon5, Children2DepartureAddon5,
  AdultArrivalAddon6, AdultStayAddon6, AdultDepartureAddon6, Children1ArrivalAddon6, Children1StayAddon6, Children1DepartureAddon6, Children2ArrivalAddon6, Children2StayAddon6, Children2DepartureAddon6,
  AdultArrivalAddon7, AdultStayAddon7, AdultDepartureAddon7, Children1ArrivalAddon7, Children1StayAddon7, Children1DepartureAddon7, Children2ArrivalAddon7, Children2StayAddon7, Children2DepartureAddon7,
  AdultArrivalAddon8, AdultStayAddon8, AdultDepartureAddon8, Children1ArrivalAddon8, Children1StayAddon8, Children1DepartureAddon8, Children2ArrivalAddon8, Children2StayAddon8, Children2DepartureAddon8,
  AdultArrivalAddon9, AdultStayAddon9, AdultDepartureAddon9, Children1ArrivalAddon9, Children1StayAddon9, Children1DepartureAddon9, Children2ArrivalAddon9, Children2StayAddon9, Children2DepartureAddon9,
  ArrivalPacketNumber,StayPacketNumber, DeparturePacketNumber)
  Values (@NewProductNumber, @DateStamp, @RoomtypeNumber,
  @AdultPrice1, @AdultPrice2, @AdultPrice3, @AdultPrice4, @AdultPrice5, @AdultPrice6, @AdultPrice7, @AdultPrice8, @AdultPrice9,
  @Children1Price1, @Children1Price2, @Children1Price3, @Children1Price4, @Children1Price5, @Children1Price6, @Children1Price7, @Children1Price8, @Children1Price9,
  @Children2Price1, @Children2Price2, @Children2Price3, @Children2Price4, @Children2Price5, @Children2Price6, @Children2Price7, @Children2Price8, @Children2Price9,
  @AdultArrivalAddon, @AdultStayAddon, @AdultDepartureAddon,@Children1ArrivalAddon,@Children1StayAddon, @Children1DepartureAddon,@Children2ArrivalAddon,@Children2StayAddon, @Children2DepartureAddon,
  @AdultArrivalAddon2, @AdultStayAddon2, @AdultDepartureAddon2, @Children1ArrivalAddon2, @Children1StayAddon2, @Children1DepartureAddon2, @Children2ArrivalAddon2, @Children2StayAddon2, @Children2DepartureAddon2,
  @AdultArrivalAddon3, @AdultStayAddon3, @AdultDepartureAddon3, @Children1ArrivalAddon3, @Children1StayAddon3, @Children1DepartureAddon3, @Children2ArrivalAddon3, @Children2StayAddon3, @Children2DepartureAddon3,
  @AdultArrivalAddon4, @AdultStayAddon4, @AdultDepartureAddon4, @Children1ArrivalAddon4, @Children1StayAddon4, @Children1DepartureAddon4, @Children2ArrivalAddon4, @Children2StayAddon4, @Children2DepartureAddon4,
  @AdultArrivalAddon5, @AdultStayAddon5, @AdultDepartureAddon5, @Children1ArrivalAddon5, @Children1StayAddon5, @Children1DepartureAddon5, @Children2ArrivalAddon5, @Children2StayAddon5, @Children2DepartureAddon5,
  @AdultArrivalAddon6, @AdultStayAddon6, @AdultDepartureAddon6, @Children1ArrivalAddon6, @Children1StayAddon6, @Children1DepartureAddon6, @Children2ArrivalAddon6, @Children2StayAddon6, @Children2DepartureAddon6,
  @AdultArrivalAddon7, @AdultStayAddon7, @AdultDepartureAddon7, @Children1ArrivalAddon7, @Children1StayAddon7, @Children1DepartureAddon7, @Children2ArrivalAddon7, @Children2StayAddon7, @Children2DepartureAddon7,
  @AdultArrivalAddon8, @AdultStayAddon8, @AdultDepartureAddon8, @Children1ArrivalAddon8, @Children1StayAddon8, @Children1DepartureAddon8, @Children2ArrivalAddon8, @Children2StayAddon8, @Children2DepartureAddon8,
  @AdultArrivalAddon9, @AdultStayAddon9, @AdultDepartureAddon9, @Children1ArrivalAddon9, @Children1StayAddon9, @Children1DepartureAddon9, @Children2ArrivalAddon9, @Children2StayAddon9, @Children2DepartureAddon9,
  @ArrivalPacketNumber,@StayPacketNumber, @DeparturePacketNumber)

  Fetch Next From CopyCur
  Into @ProductNumber, @DateStamp, @RoomtypeNumber,
  @AdultPrice1, @AdultPrice2, @AdultPrice3, @AdultPrice4, @AdultPrice5, @AdultPrice6, @AdultPrice7, @AdultPrice8, @AdultPrice9,
  @Children1Price1, @Children1Price2, @Children1Price3, @Children1Price4, @Children1Price5, @Children1Price6, @Children1Price7, @Children1Price8, @Children1Price9,
  @Children2Price1, @Children2Price2, @Children2Price3, @Children2Price4, @Children2Price5, @Children2Price6, @Children2Price7, @Children2Price8, @Children2Price9,
  @AdultArrivalAddon, @AdultStayAddon, @AdultDepartureAddon,@Children1ArrivalAddon,@Children1StayAddon, @Children1DepartureAddon,@Children2ArrivalAddon,@Children2StayAddon, @Children2DepartureAddon,
  @AdultArrivalAddon2, @AdultStayAddon2, @AdultDepartureAddon2, @Children1ArrivalAddon2, @Children1StayAddon2, @Children1DepartureAddon2, @Children2ArrivalAddon2, @Children2StayAddon2, @Children2DepartureAddon2,
  @AdultArrivalAddon3, @AdultStayAddon3, @AdultDepartureAddon3, @Children1ArrivalAddon3, @Children1StayAddon3, @Children1DepartureAddon3, @Children2ArrivalAddon3, @Children2StayAddon3, @Children2DepartureAddon3,
  @AdultArrivalAddon4, @AdultStayAddon4, @AdultDepartureAddon4, @Children1ArrivalAddon4, @Children1StayAddon4, @Children1DepartureAddon4, @Children2ArrivalAddon4, @Children2StayAddon4, @Children2DepartureAddon4,
  @AdultArrivalAddon5, @AdultStayAddon5, @AdultDepartureAddon5, @Children1ArrivalAddon5, @Children1StayAddon5, @Children1DepartureAddon5, @Children2ArrivalAddon5, @Children2StayAddon5, @Children2DepartureAddon5,
  @AdultArrivalAddon6, @AdultStayAddon6, @AdultDepartureAddon6, @Children1ArrivalAddon6, @Children1StayAddon6, @Children1DepartureAddon6, @Children2ArrivalAddon6, @Children2StayAddon6, @Children2DepartureAddon6,
  @AdultArrivalAddon7, @AdultStayAddon7, @AdultDepartureAddon7, @Children1ArrivalAddon7, @Children1StayAddon7, @Children1DepartureAddon7, @Children2ArrivalAddon7, @Children2StayAddon7, @Children2DepartureAddon7,
  @AdultArrivalAddon8, @AdultStayAddon8, @AdultDepartureAddon8, @Children1ArrivalAddon8, @Children1StayAddon8, @Children1DepartureAddon8, @Children2ArrivalAddon8, @Children2StayAddon8, @Children2DepartureAddon8,
  @AdultArrivalAddon9, @AdultStayAddon9, @AdultDepartureAddon9, @Children1ArrivalAddon9, @Children1StayAddon9, @Children1DepartureAddon9, @Children2ArrivalAddon9, @Children2StayAddon9, @Children2DepartureAddon9,
  @ArrivalPacketNumber,@StayPacketNumber, @DeparturePacketNumber
End

Close CopyCur
DeAllocate CopyCur

-- ProductPOSXtab --

Declare @PointOfSaleNumber Int
Declare CopyCur Cursor Forward_only FOR
Select ProductNumber, PointOfSaleNumber From ProductPOSXtab WITH (NOLOCK)
Where ProductNumber = @OldProductNumber
Open CopyCur
Fetch Next From CopyCur
Into
@ProductNumber, @PointOfSaleNumber 
While (@@Fetch_status=0)
Begin
Insert Into ProductPOSXtab Values (
@NewProductNumber, @PointOfSaleNumber)
Fetch Next From CopyCur
Into @ProductNumber,  @PointOfSaleNumber
End;
Close CopyCur
DeAllocate CopyCur


-- ProductSegmentsXTab --

Declare @SegmentNumber Int
Declare CopyCur Cursor Forward_only FOR
Select ProductNumber, SegmentNumber From ProductSegmentsXTab WITH (NOLOCK)
Where ProductNumber = @OldProductNumber
Open CopyCur
Fetch Next From CopyCur
Into
@ProductNumber, @SegmentNumber 
While (@@Fetch_status=0)
Begin
Insert Into ProductSegmentsXTab Values (
@NewProductNumber, @SegmentNumber)
Fetch Next From CopyCur
Into @ProductNumber,  @SegmentNumber
End;
Close CopyCur
DeAllocate CopyCur


-- ProductMinimumAvailableRoomsXTab --

Declare @ProductMinimumDaysNumber Int
Declare @MinimumNumberOfRooms Int
Declare CopyCur Cursor Forward_only FOR
Select ProductNumber, ProductMinimumDaysNumber,MinimumNumberOfRooms From ProductMinimumAvailableRoomsXTab WITH (NOLOCK)
Where ProductNumber = @OldProductNumber
Open CopyCur
Fetch Next From CopyCur
Into
@ProductNumber, @ProductMinimumDaysNumber, @MinimumNumberOfRooms 
While (@@Fetch_status=0)
Begin
Insert Into ProductMinimumAvailableRoomsXTab Values (
@NewProductNumber, @ProductMinimumDaysNumber, @MinimumNumberOfRooms)
Fetch Next From CopyCur
Into @ProductNumber,  @ProductMinimumDaysNumber, @MinimumNumberOfRooms
End;
Close CopyCur
DeAllocate CopyCur

-- ProductHotelXTAB

DECLARE @HotelCustomerNumber INT

DECLARE CopyCursor CURSOR FAST_FORWARD READ_ONLY FOR
  SELECT ProductHotelXTAB.HotelCustomerNumber
  FROM ProductHotelXTAB WITH (NOLOCK)
  WHERE ProductNumber = @OldProductNumber
OPEN CopyCursor

FETCH NEXT FROM CopyCursor INTO @HotelCustomerNumber
WHILE @@FETCH_STATUS = 0
BEGIN
  INSERT INTO ProductHotelXTAB (ProductNumber, HotelCustomerNumber) VALUES (@NewProductNumber, @HotelCustomerNumber)
  FETCH NEXT FROM CopyCursor INTO @HotelCustomerNumber
END
CLOSE CopyCursor
DEALLOCATE CopyCursor

-- ProductExtended
SELECT *
INTO #TempProductExtended
FROM ProductExtended WITH (NOLOCK)
WHERE FK_ProductNumber = @OldProductNumber

UPDATE #TempProductExtended
SET FK_ProductNumber = @NewProductNumber
WHERE FK_ProductNumber = @OldProductNumber

INSERT INTO ProductExtended SELECT * FROM #TempProductExtended

DROP TABLE #TempProductExtended

