use jinan_gt SELECT * FROM TCompany SELECT *INTO #ConsumeBill FROM TConsumeBill WHERE FCompId = dbo.FNCompId('023') AND FWorkDate BETWEEN '2022-03-01' AND '2022-12-31' AND FCardId = 0 AND FState = 1 AND FBillId IN(SELECT FBillId FROM TConsumeItemPayment WHERE FPayTypeId NOT IN(6,61,9,11) AND FPayTypeId NOT IN(SELECT FId FROM TPayAccount WHERE FIsAccount = 1)) ALTER TABLE #ConsumeBill ADD FOldBillId BIGINT SELECT * INTO #ConsumeItem FROM TConsumeItem WHERE FBillId IN(SELECT FBillId FROM #ConsumeBill) SELECT * INTO #ConsumeItemEmployee FROM TConsumeItemEmployee WHERE FBillId IN(SELECT FBillId FROM #ConsumeBill) SELECT * INTO #ConsumeItemPayment FROM TConsumeItemPayment WHERE FBillId IN(SELECT FBillId FROM #ConsumeBill) SELECT * INTO #ConsumeGoods FROM TConsumeGoods WHERE FBillId IN(SELECT FBillId FROM #ConsumeBill) SELECT * INTO #ConsumeGoodsEmployee FROM TConsumeGoodsEmployee WHERE FBillId IN(SELECT FBillId FROM #ConsumeBill) SELECT * INTO #ConsumeGoodsPayment FROM TConsumeGoodsPayment WHERE FBillId IN(SELECT FBillId FROM #ConsumeBill) ALTER TABLE #ConsumeItem ADD FOldId BIGINT ALTER TABLE #ConsumeItemEmployee ADD FOldId BIGINT ALTER TABLE #ConsumeItemPayment ADD FOldId BIGINT ALTER TABLE #ConsumeGoods ADD FOldId BIGINT ALTER TABLE #ConsumeGoodsEmployee ADD FOldId BIGINT ALTER TABLE #ConsumeGoodsPayment ADD FOldId BIGINT UPDATE #ConsumeBill SET FOldBillId = FBillId UPDATE #ConsumeItem SET FOldId = FId UPDATE #ConsumeItemEmployee SET FOldId = FId UPDATE #ConsumeItemPayment SET FOldId = FId UPDATE #ConsumeGoods SET FOldId = FId UPDATE #ConsumeGoodsEmployee SET FOldId = FId UPDATE #ConsumeGoodsPayment SET FOldId = FId UPDATE #ConsumeBill SET FBillId = dbo.FNNewId() UPDATE #ConsumeBill SET FMasterId = FBillId UPDATE #ConsumeBill SET FMemId = 0,FMemNO = 'É¢¿Í',FCustTelephone = '',FCustName = '' UPDATE #ConsumeItem SET FId = dbo.FNNewId() UPDATE #ConsumeItemEmployee SET FId = dbo.FNNewId() UPDATE #ConsumeItemPayment SET FId = dbo.FNNewId() UPDATE #ConsumeGoods SET FId = dbo.FNNewId() UPDATE #ConsumeGoodsEmployee SET FId = dbo.FNNewId() UPDATE #ConsumeGoodsPayment SET FId = dbo.FNNewId() UPDATE A SET A.FBillId = B.FBillID FROM #ConsumeItem AS A,#ConsumeBill AS B WHERE A.FBillId = B.FOldBillId UPDATE A SET A.FDetailId = B.FId, A.FBillId = B.FBillID FROM #ConsumeItemEmployee AS A,#ConsumeItem AS B WHERE A.FDetailId = B.FOldId UPDATE A SET A.FDetailId = B.FId, A.FBillId = B.FBillId FROM #ConsumeItemPayment AS A,#ConsumeItem AS B WHERE A.FDetailId = B.FOldId UPDATE A SET A.FBillId = B.FBillID FROM #ConsumeGoods AS A,#ConsumeBill AS B WHERE A.FBillId = B.FOldBillId UPDATE A SET A.FDetailId = B.FId, A.FBillId = B.FBillID FROM #ConsumeGoodsEmployee AS A,#ConsumeGoods AS B WHERE A.FDetailId = B.FOldId UPDATE A SET A.FDetailId = B.FId, A.FBillId = B.FBillId FROM #ConsumeGoodsPayment AS A,#ConsumeGoods AS B WHERE A.FDetailId = B.FOldId UPDATE #ConsumeBill SET FCompID = DBO.FNCompId('002') EXEC PCopyTable 'TConsumeBill','#ConsumeBill','' EXEC PCopyTable 'TConsumeItem','#ConsumeItem','' EXEC PCopyTable 'TConsumeItemEmployee','#ConsumeItemEmployee','' EXEC PCopyTable 'TConsumeItemPayment','#ConsumeItemPayment','' EXEC PCopyTable 'TConsumeGoods','#ConsumeGoods','' EXEC PCopyTable 'TConsumeGoodsEmployee','#ConsumeGoodsEmployee','' EXEC PCopyTable 'TConsumeGoodsPayment','#ConsumeGoodsPayment',''