use jinan_meishang SELECT * FROM cd236.KunMing_YongSheng.dbo.TCompany SELECT * FROM TCompany UPDATE TCompany SET FNo = '001' WHERE FNo = '000' drop table #Company CREATE TABLE #Company ( FCompId BIGINT ) INSERT #Company SELECT fiD FROM cd236.KunMing_YongSheng.DBO.TCompany WHERE FNo IN('002','008','009') --门店 SELECT * FROM TCompany SELECT * INTO #Comp FROM cd236.KunMing_YongSheng.dbo.TCompany WHERE FId IN(SELECT FCompId FROM #Company) UPDATE #Comp SET FNo = 'FH' + FNo EXEC PCopyTable 'TCompany','#Comp',' ' SELECT * FROM TCompany --用户 EXEC PCopyTable 'TAccessDict','cd236.KunMing_YongSheng.dbo.TAccessDict',' AND FKey NOT IN(SELECT FKey FROM TAccessDict)' SELECT *INTO #User FROM cd236.KunMing_YongSheng.dbo.TUser WHERE 1=1 AND FId IN(SELECT FUserId FROM cd236.KunMing_YongSheng.dbo.TUserAllowCompany WHERE FCompId IN(SELECT FCompId FROM #Company)) UPDATE #User SET FNo = 'FH' + FNo WHERE FNo IN(SELECT FNo FROM TUser) EXEC PCopyTable 'TUser','#User','' EXEC PCopyTable 'TRole','cd236.KunMing_YongSheng.dbo.TRole','AND FId not in(SELECT FId FROM TRole) AND FId IN(SELECT FRoleId FROM cd236.KunMing_YongSheng.dbo.TUserRole WHERE FUserId IN(SELECT FId FROM TUser))' EXEC PCopyTable 'TUserRole','cd236.KunMing_YongSheng.dbo.TUserRole','AND FId NOT IN(SELECT FId FROM TUserRole) AND FUserId IN(SELECT FId FROM TUser) ' EXEC PCopyTable 'TRoleAccess','cd236.KunMing_YongSheng.dbo.TRoleAccess','AND FRoleId NOT IN(SELECT FRoleId FROM TRoleAccess) AND FRoleId IN(SELECT FId FROM TRole) ' EXEC PCopyTable 'TUserAllowCompany','cd236.KunMing_YongSheng.dbo.TUserAllowCompany',' AND FCompId IN( SELECT FCompId FROM #Company)' --确定要要导的会员 DROP TABLE #MemberCard DROP TABLE #MemberCardD DROP TABLE #MemberCourse DROP TABLE #MemberCourseD DROP TABLE #Member --会员 SELECT * INTO #MemberCardI FROM cd236.KunMing_YongSheng.dbo.TMemberCard WHERE FCompId IN(SELECT FCompId FROM #Company) --AND FTypeId IN(SELECT FId FROM TMemberCardType WHERE FNo IN('001','208','202','203','204','207','206','205','210','209')) SELECT * INTO #MemberCourseI FROM cd236.KunMing_YongSheng.dbo.TMemberCourse WHERE FCompId IN(SELECT FCompId FROM #Company) --AND FPurchaseDate < '2019-08-04' --跨点的会员,需要删除 SELECT * INTO #MemberCardD FROM cd236.KunMing_YongSheng.dbo.TMemberCard WHERE FCardId NOT IN(SELECT FCardId FROM #MemberCardI) AND (FCardId IN(SELECT A.FCardId FROM cd236.KunMing_YongSheng.DBO.TConsumeBill AS B,cd236.KunMing_YongSheng.DBO.TConsumeItemPayment AS A WHERE A.FBillId = B.FBillId AND B.FCompId IN(SELECT FCompId FROM #Company) AND A.FCardId > 0 AND B.FMemId > 0 UNION ALL SELECT A.FCardId FROM cd236.KunMing_YongSheng.DBO.TConsumeBill AS B,cd236.KunMing_YongSheng.DBO.TConsumeGoodsPayment AS A WHERE A.FBillId = B.FBillId AND B.FCompId IN(SELECT FCompId FROM #Company) AND A.FCardId > 0 AND B.FMemId > 0 UNION ALL SELECT A.FCardId FROM TMemberSaleCard AS A,TMemberSaleBill AS T WHERE T.FBillId = A.FBillId AND T.FCompId IN(SELECT FCompId FROM #Company) ) ) SELECT * INTO #MemberCourseD FROM cd236.KunMing_YongSheng.dbo.TMemberCourse WHERE FId NOT IN(SELECT FId FROM #MemberCourseI) AND (FId IN(SELECT A.FMemCourseId FROM cd236.KunMing_YongSheng.DBO.TConsumeBill AS B,cd236.KunMing_YongSheng.DBO.TConsumeItem AS A WHERE A.FBillId = B.FBillId AND B.FCompId IN(SELECT FCompId FROM #Company) AND A.FMemCourseId > 0 AND B.FMemId > 0) ) SELECT * INTO #MemberCard FROM #MemberCardI UNION SELECT * FROM #MemberCarDd SELECT * INTO #MemberCourse FROM #MemberCourseI UNION SELECT * FROM #MemberCourseD SELECT * INTO #Member FROM cd236.KunMing_YongSheng.dbo.TMember WHERE FMemId IN( SELECT FMemID FROM #MemberCard UNION ALL SELECT FMemId FROM #MemberCourse GROUP BY FMemId ) and FMemId not in(select fmemid from #member) --end --账户 SELECT * INTO #PayAccount FROM TPayAccount WHERE 1=0 INSERT #PayAccount(FId,FNo,FName,FDescription,FIsAccount,FAllowEdit,FItemBizRate,FGoodsBizRate,FCardBizRate,FItemPerfRate,FGoodsPerfRate,FCardPerfRate,FItemPointRate,FGoodsPointRate,FCardPointRate,FIsCashIncome,FIsBizIncome,FIsCashPerf,FIsLabor,FCourseIsLabor,FEnabled,FOrder ) SELECT FId,FNo,FName,FDescription,FIsAccount,FAllowEdit,FItemBizRate,FGoodsBizRate,FCardBizRate,FItemPerfRate,FGoodsPerfRate,FCardPerfRate,FItemPointRate,FGoodsPointRate,FCardPointRate,FIsCashIncome,FIsBizIncome,FIsCashPerf,FIsLabor,FCourseIsLabor,FEnabled,FOrder FROM cd236.KunMing_YongSheng.dbo.TPayAccount WHERE 1=1 AND FId NOT IN(SELECT FId FROM TPayAccount) EXEC PDropColumn 'TPayAccount','FBKAcctId' EXEC PDropColumn 'TPayAccount','FBKPayNo' UPDATE #PayAccount SET FNo = 'HC' + FNo WHERE FId NOT IN(SELECT FId FROM TPayAccount) AND FNo IN(SELECT FNo FROM TPayAccount) EXEC PCopyTable 'TPayAccount','#PayAccount',' ' --基本类别 --产品单位,项目类别,折扣类别, SELECT * INTO #Unit FROM TBasicType WHERE FKey like 'GoodsUnit' AND FId NOT IN(SELECT FUnitId FROM TGoods ) DROP TABLE #Keys CREATE TABLE #Keys ( FKey VARCHAR(100) ) INSERT #Keys SELECT 'ItemType' UNION ALL SELECT 'GoodsType' UNION ALL SELECT 'ItemDiscountType' UNION ALL SELECT 'GoodsDiscountType' UNION ALL SELECT 'GoodsUnit' UNION ALL SELECT 'Department' UNION ALL SELECT 'Position' UNION ALL SELECT 'Department' INSERT #Keys SELECT 'Expenses' WHERE EXISTS(SELECT 1 FROM cd236.KunMing_YongSheng.dbo.TExpensesBill) INSERT #Keys SELECT 'OtherIncom' WHERE EXISTS(SELECT 1 FROM cd236.KunMing_YongSheng.dbo.TOtherIncomeBill) INSERT #Keys SELECT 'Store' WHERE EXISTS(SELECT 1 FROM cd236.KunMing_YongSheng.dbo.TStockInBill) --基本类别资料 DROP TABLE #BasicType SELECT * INTO #BasicType FROM cd236.KunMing_YongSheng.dbo.TBasicType WHERE 1=1 AND FKey IN(SELECT FKey FROM #Keys) AND FId NOT IN(SELECT FId FROM TBasicType) UPDATE #BasicType SET FNo = 'HC' + FNo WHERE FKey+'-' + FNo IN(SELECT FKey + '-' + FNo FROM TBasicType) EXEC PCopyTable 'TBasicType','#BasicType','' DROP TABLE #BasicType EXEC PCopyTable 'TBasicTypeSub','cd236.KunMing_YongSheng.dbo.TBasicTypeSub', ' AND FBasicTypeId IN(SELECT FId FROM cd236.KunMing_YongSheng.dbo.TBasicType WHERE FKey IN(SELECT FKey FROM #Keys) ) AND FCompId IN(SELECT 1 UNION ALL SELECT FCompId FROM #Company) AND FBasicTypeId NOT IN(SELECT FBasicTypeId FROM TBasicTypeSub)' --储值卡类别 drop table #MemberCardType SELECT * INTO #MemberCardType FROM cd236.KunMing_YongSheng.dbo.TMemberCardType WHERE FId > 10 AND FId IN(SELECT FTypeId FROM #MemberCard ) UPDATE #MemberCardType SET FNo = 'YS' + FNo WHERE FNo IN(SELECT FNo FROM TMemberCardType) EXEC PCopyTable 'TMemberCardType','#MemberCardType',' ' SELECT * INTO #MemberCardTypeSub FROM cd236.KunMing_YongSheng.dbo.TMemberCardTypeSub WHERE 1=1 AND FCardTypeId IN (SELECT FId FROM TMemberCardType) AND FCardTypeId > 9 AND FCompId IN(SELECT 1 UNION ALL SELECT FCompId FROM #Company) EXEC PCopyTable 'TMemberCardTypeSub','#MemberCardTypeSub',' ' SELECT * FROM # --项目 SELECT * INTO #Item FROM cd236.KunMing_YongSheng.dbo.TItem WHERE 1=1 AND FId NOT IN (SELECT FId FROM TItem) AND FId IN(SELECT FItemId FROM #MemberCourse) UPDATE #Item SET FNo = 'YS' + FNo WHERE FNo IN (SELECT FNo FROM TItem) EXEC PCopyTable 'TItem','#Item',' ' EXEC PDropColumn 'TItem','FReturnInterval' SELECT * INTO #ItemSub FROM cd236.KunMing_YongSheng.dbo.TItemSub WHERE 1=1 AND FId > 0 AND FItemId IN(SELECT FId FROM TItem) AND FCompId IN(SELECT 1 UNION ALL SELECT FCompId FROM #Company) EXEC PCopyTable 'TItemSub','#ItemSub',' ' SELECT * INTO #Course FROM cd236.KunMing_YongSheng.dbo.TCourse WHERE 1=1 AND FId NOT IN (SELECT FId FROM TCourse ) AND FItemId IN(SELECT FId FROM TItem) --疗程 UPDATE #Course SET FNo = 'YS' + FNo WHERE FNo IN(SELECT FNo FROM TCourse) EXEC PCopyTable 'TCourse','#Course',' ' --产品 SELECT *into #Goods FROM cd236.KunMing_YongSheng.dbo.TGoods WHERE FId > 0 UPDATE #Goods SET FNo = 'HC' + FNo WHERE FNo IN(SELECT FNo FROM TGoods) EXEC PCopyTable 'TGoods','#Goods','' EXEC PCopyTable 'TGoodsSub','cd236.KunMing_YongSheng.dbo.TGoodsSub',' AND FId > 0 AND FCompId IN(SELECT 1 UNION ALL SELECT FCompId FROM #Company)' EXEC PCopyTable 'TGoodsMultiUnit','cd236.KunMing_YongSheng.dbo.TGoodsMultiUnit',' AND FId > 0 ' --员工 SELECT * INTO #Employee FROM cd236.KunMing_YongSheng.dbo.TEmployee where 1=1 AND FId IN(SELECT FEmpId FROM cd236.KunMing_YongSheng.dbo.TEmployeeSub WHERE FCompID IN(select FCompId FROM #Company)) UPDATE #Employee SET FNo= 'HC' + FNo WHERE FId > 0 and FNo IN(SELECT FNo FROM TEmployee) ALTER TABLE TEmployee DROP CONSTRAINT FK_EMPLOYE_ROLE_ID ALTER TABLE TEmployee ADD CONSTRAINT FK_EMPLOYE_ROLE_ID FOREIGN KEY (FRoleId) REFERENCES TEmployeeRole (FId) PDropColumn 'TEmployee','FIntroducer' EXEC PCopyTable 'TEmployee','#Employee',' ' EXEC PCopyTable 'TEmployeeSub','cd236.KunMing_YongSheng.dbo.TEmployeeSub',' AND FCompID IN(select FCompId FROM #Company) ' --基本提成 EXEC PCopyTable 'TItemBaseComm','cd236.KunMing_YongSheng.dbo.TItemBaseComm',' AND FCompId IN(SELECT 1 UNION ALL select FCompId FROM #Company) ' EXEC PCopyTable 'TGoodsBaseComm','cd236.KunMing_YongSheng.dbo.TGoodsBaseComm',' AND FId > 0 AND FCompId IN(SELECT 1 UNION ALL select FCompId FROM #Company)' EXEC PCopyTable 'TMemberCardTypeBaseComm','cd236.KunMing_YongSheng.dbo.TMemberCardTypeBaseComm',' AND FId > 0 AND FCompId IN(SELECT 1 UNION ALL select FCompId FROM #Company)' EXEC PCopyTable 'TCourseSaleBaseComm','cd236.KunMing_YongSheng.dbo.TCourseSaleBaseComm',' AND FId > 0 AND FCompId IN(SELECT 1 UNION ALL select FCompId FROM #Company)' EXEC PCopyTable 'TCourseConsBaseComm','cd236.KunMing_YongSheng.dbo.TCourseConsBaseComm',' AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company) ' --项目提成方案 EXEC PCopyTable 'TItemCommSchemeMaster','cd236.KunMing_YongSheng.dbo.TItemCommSchemeMaster',' AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company) ' EXEC PCopyTable 'TItemCommSchemeMaster','cd236.KunMing_YongSheng.dbo.TItemCommSchemeMaster',' AND FId = 0' EXEC PCopyTable 'TItemCommSchemeSection','cd236.KunMing_YongSheng.dbo.TItemCommSchemeSection',' AND FId = 0 ' EXEC PCopyTable 'TItemCommSchemeSection','cd236.KunMing_YongSheng.dbo.TItemCommSchemeSection',' AND FMasterId IN(SELECT FId FROM TItemCommSchemeMaster) AND FId != 0 ' EXEC PCopyTable 'TItemCommSchemeDetail','cd236.KunMing_YongSheng.dbo.TItemCommSchemeDetail',' AND FMasterId IN(SELECT FId FROM TItemCommSchemeMaster) ' EXEC PCopyTable 'TItemCommSchemeExcept','cd236.KunMing_YongSheng.dbo.TItemCommSchemeExcept',' AND FMasterId IN(SELECT FId FROM TItemCommSchemeMaster) ' EXEC PCopyTable 'TItemCommSchemeExtra','cd236.KunMing_YongSheng.dbo.TItemCommSchemeExtra',' AND FMasterId IN(SELECT FId FROM TItemCommSchemeMaster) ' --产品提成方案 EXEC PCopyTable 'TGoodsCommSchemeMaster','cd236.KunMing_YongSheng.dbo.TGoodsCommSchemeMaster',' AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company) ' EXEC PCopyTable 'TGoodsCommSchemeMaster','cd236.KunMing_YongSheng.dbo.TGoodsCommSchemeMaster',' AND FId=0 ' EXEC PCopyTable 'TGoodsCommSchemeSection','cd236.KunMing_YongSheng.dbo.TGoodsCommSchemeSection',' AND FId = 0 ' EXEC PCopyTable 'TGoodsCommSchemeSection','cd236.KunMing_YongSheng.dbo.TGoodsCommSchemeSection',' AND FMasterId IN(SELECT FId FROM TGoodsCommSchemeMaster) AND FId != 0 ' EXEC PCopyTable 'TGoodsCommSchemeDetail','cd236.KunMing_YongSheng.dbo.TGoodsCommSchemeDetail',' AND FMasterId IN(SELECT FId FROM TGoodsCommSchemeMaster) AND FId != 0 ' --储值卡提成方案 EXEC PCopyTable 'TCardTypeCommSchemeMaster','cd236.KunMing_YongSheng.dbo.TCardTypeCommSchemeMaster',' AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company) ' EXEC PCopyTable 'TCardTypeCommSchemeSection','cd236.KunMing_YongSheng.dbo.TCardTypeCommSchemeSection',' AND FId IN(SELECT FId FROM TCardTypeCommSchemeMaster) ' EXEC PCopyTable 'TCardTypeCommSchemeDetail','cd236.KunMing_YongSheng.dbo.TCardTypeCommSchemeDetail',' AND FId IN(SELECT FId FROM TCardTypeCommSchemeMaster) ' --项目折扣 EXEC PCopyTable 'TItemDiscountMaster','cd236.KunMing_YongSheng.dbo.TItemDiscountMaster',' AND FCompId IN(select FCompId FROM #Company) ' EXEC PCopyTable 'TItemDiscountMid','cd236.KunMing_YongSheng.dbo.TItemDiscountMid',' AND FParentId IN(SELECT FId FROM TItemDiscountMaster) ' EXEC PCopyTable 'TItemDiscountDetail','cd236.KunMing_YongSheng.dbo.TItemDiscountDetail',' AND FParentId IN(select FId FROM TItemDiscountMid) ' --产品折扣 EXEC PCopyTable 'TGoodsDiscountMaster','cd236.KunMing_YongSheng.dbo.TGoodsDiscountMaster',' AND FCompId IN(SELECT FCompId FROM #Company) ' EXEC PCopyTable 'TGoodsDiscountDetail','cd236.KunMing_YongSheng.dbo.TGoodsDiscountDetail',' AND FMasterId IN(SELECT FId FROM TGoodsDiscountMaster) ' --控制 EXEC PCopyTable 'TBasicDataSyncControl','cd236.KunMing_YongSheng.dbo.TBasicDataSyncControl','' EXEC PInitBasicDataSyncControl UPDATE #Member SET FMemNO = 'YS' + FMemNO WHERE FMemNO IN(SELECT FMemNO FROM TMember) OR FMemNo IN(SELECT FCardNo FROM TMemberCard) UPDATE #MemberCard SET FCardNo = 'YS' + FCardNo WHERE FCardNo IN(SELECT FCardNo FROM TMemberCard) SELECT * FROM #MemberCardD WHERE FMemId NOT IN(SELECT FMemId FROM TMember) PDropColumn TMember,PWRESET DELETE TMember WHERE FMemId IN(SELECT FMemId FROM #member) EXEC PCopyTable 'TMember','#Member',' AND FMemId > 0 AND FMemId NOT IN(SELECT FMemID from tmember) ' EXEC PCopyTable 'TMemberCard','#MemberCard',' AND FCardId > 0 ' EXEC PCopyTable 'TMemberCardAccount','cd236.KunMing_YongSheng.dbo.TMemberCardAccount',' AND FCardId IN(SELECT FCardId FROM #MemberCard) ' EXEC PCopyTable 'TMemberCardAcctHist','cd236.KunMing_YongSheng.dbo.TMemberCardAcctHist',' AND FCardId IN(SELECT FCardId FROM #MemberCard) ' SELECT * FROM #MemberCourse WHERE FMemId NOT IN(SELECT FMemId FROM TMember) EXEC PCopyTable 'TMemberCoursePack','cd236.KunMing_YongSheng.dbo.TMemberCoursePack',' AND FMemId IN(SELECT FMemId FROM #Member)' EXEC PCopyTable 'TMemberGoods','cd236.KunMing_YongSheng.dbo.TMemberGoods',' AND FMemId IN(SELECT FMemId FROM #Member)' EXEC PCopyTable 'TMemberCourse','cd236.KunMing_YongSheng.dbo.TMemberCourse',' AND FId IN(SELECT FId FROM #MemberCourse) ' EXEC PCopyTable 'TMemberCourseLog','cd236.KunMing_YongSheng.dbo.TMemberCourseLog',' AND FCardId IN(SELECT FId FROM #MemberCourse) ' EXEC PCopyTable 'TMemberEmployee','cd236.KunMing_YongSheng.dbo.TMemberEmployee',' AND FMemId IN(SELECT FMemId FROM #Member) ' EXEC PCopyTable 'TMemberPhoto','cd236.KunMing_YongSheng.dbo.TMemberPhoto',' AND FMemId IN(SELECT FMemId FROM #Member) ' EXEC PCopyTable 'TMemberPointHist','cd236.KunMing_YongSheng.dbo.TMemberPointHist',' AND FMemId IN(SELECT FMemId FROM #Member)' EXEC PCopyTable 'TMemberTransHist','cd236.KunMing_YongSheng.dbo.TMemberTransHist',' AND FMemId IN(SELECT FMemId FROM #Member) ' EXEC PCopyTable 'TMemberTransHistPayment','cd236.KunMing_YongSheng.dbo.TMemberTransHistPayment','AND FMemId IN(SELECT FMemId FROM #Member) ' EXEC PCopyTable 'TMemberOldTransHist','cd236.KunMing_YongSheng.dbo.TMemberOldTransHist',' AND FMemId IN(SELECT FMemId FROM #Member) ' EXEC PCopyTable 'TMemberCardOldAcctHist','cd236.KunMing_YongSheng.dbo.TMemberCardOldAcctHist',' AND FMemId IN(SELECT FMemId FROM #Member) ' EXEC PCopyTable 'TMemberArrear','cd236.KunMing_YongSheng.dbo.TMemberArrear',' AND FMemId IN(SELECT FMemId FROM #Member) ' EXEC PCopyTable 'TMemberRepay','cd236.KunMing_YongSheng.dbo.TMemberRepay',' AND FMemId IN(SELECT FMemId FROM #Member) ' EXEC PCopyTable 'TMemberArrearEmployee','cd236.KunMing_YongSheng.dbo.TMemberArrearEmployee',' AND FMemId IN(SELECT FMemId FROM #Member) ' --开卡 EXEC PCopyTable 'TMemberSaleBill','cd236.KunMing_YongSheng.dbo.TMemberSaleBill',' AND FCompId In(SELECT FCompId FROM #Company) ' EXEC PCopyTable 'TMemberSaleCard','cd236.KunMing_YongSheng.dbo.TMemberSaleCard',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) ' EXEC PCopyTable 'TMemberSaleCourse','cd236.KunMing_YongSheng.dbo.TMemberSaleCourse',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) ' EXEC PCopyTable 'TMemberSaleCourseGoods','cd236.KunMing_YongSheng.dbo.TMemberSaleCourseGoods',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) ' EXEC PCopyTable 'TMemberSaleCoursePack','cd236.KunMing_YongSheng.dbo.TMemberSaleCoursePack',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) ' EXEC PCopyTable 'TMemberSaleDetailSplit','cd236.KunMing_YongSheng.dbo.TMemberSaleDetailSplit',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) ' EXEC PCopyTable 'TMemberSaleEmployee','cd236.KunMing_YongSheng.dbo.TMemberSaleEmployee',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) ' EXEC PCopyTable 'TMemberSaleExchange','cd236.KunMing_YongSheng.dbo.TMemberSaleExchange',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) ' EXEC PCopyTable 'TMemberSaleExchangeSource','cd236.KunMing_YongSheng.dbo.TMemberSaleExchangeSource','AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) ' EXEC PCopyTable 'TMemberSaleFreeItem','cd236.KunMing_YongSheng.dbo.TMemberSaleFreeItem',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) ' EXEC PCopyTable 'TMemberSaleInfo','cd236.KunMing_YongSheng.dbo.TMemberSaleInfo',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) ' EXEC PCopyTable 'TMemberSalePayment','cd236.KunMing_YongSheng.dbo.TMemberSalePayment',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) ' EXEC PCopyTable 'TMemberSaleRepay','cd236.KunMing_YongSheng.dbo.TMemberSaleRepay','AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) ' EXEC PCopyTable 'TMemberSaleDetailPayment','cd236.KunMing_YongSheng.dbo.TMemberSaleDetailPayment','AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) ' PDropColumn 'TConsumeBill','FRoomId' SELECT * FROM cd236.KunMing_YongSheng.dbo.TConsumeItemPayment WHERE FBillId = 5571943431087352348 SELECT * FROM cd236.KunMing_YongSheng.dbo.TConsumeItemPayment WHERE FBillId = 5411882309614627079 SELECT * FROM cd236.KunMing_YongSheng.dbo.TConsumeBill WHERE FCardId NOT IN(SELECT FCardId FROM TMemberCard) AND FCompId IN(SELECT FCompId FROM #Company) --消费 EXEC PCopyTable 'TConsumeBill','cd236.KunMing_YongSheng.dbo.TConsumeBill',' AND FCompId IN(SELECT FCompId FROM #Company) ' EXEC PCopyTable 'TConsumeItem','cd236.KunMing_YongSheng.dbo.TConsumeItem',' AND FBillId IN(SELECT FBillId FROM TConsumeBill) ' EXEC PCopyTable 'TConsumeItemPayment','cd236.KunMing_YongSheng.dbo.TConsumeItemPayment',' AND FBillId IN(SELECT FBillId FROM TConsumeBill) ' EXEC PCopyTable 'TConsumeItemEmployee','cd236.KunMing_YongSheng.dbo.TConsumeItemEmployee',' AND FBillId IN(SELECT FBillId FROM TConsumeBill) ' EXEC PCopyTable 'TConsumeGoods','cd236.KunMing_YongSheng.dbo.TConsumeGoods',' AND FBillId IN(SELECT FBillId FROM TConsumeBill) ' EXEC PCopyTable 'TConsumeGoodsEmployee','cd236.KunMing_YongSheng.dbo.TConsumeGoodsEmployee',' AND FBillId IN(SELECT FBillId FROM TConsumeBill) ' EXEC PCopyTable 'TConsumeGoodsPayment','cd236.KunMing_YongSheng.dbo.TConsumeGoodsPayment',' AND FBillId IN(SELECT FBillId FROM TConsumeBill) ' PDROPCOLUMN 'TConsumeItem','FMemComboItemId' ALTER TABLE TConsumeItem ADD FMemComboItemId BIGINT --开支 EXEC PCopyTable 'TOtherIncomeBill','cd236.KunMing_YongSheng.dbo.TOtherIncomeBill',' ' EXEC PCopyTable 'TOtherIncomeDetail','cd236.KunMing_YongSheng.dbo.TOtherIncomeDetail',' ' EXEC PCopyTable 'TOtherIncomePayment','cd236.KunMing_YongSheng.dbo.TOtherIncomePayment',' ' EXEC PCopyTable 'TExpensesBill','cd236.KunMing_YongSheng.dbo.TExpensesBill',' ' EXEC PCopyTable 'TExpensesDetail','cd236.KunMing_YongSheng.dbo.TExpensesDetail',' ' EXEC PCopyTable 'TExpensesPayment','cd236.KunMing_YongSheng.dbo.TExpensesPayment',' ' --库存 EXEC PCopyTable 'TInventory','cd236.KunMing_YongSheng.dbo.TInventory',' ' EXEC PCopyTable 'TInventoryLog','cd236.KunMing_YongSheng.dbo.TInventoryLog',' ' --库存历史 --入库单 EXEC PCopyTable 'TStockInBill','cd236.KunMing_YongSheng.dbo.TStockInBill',' ' EXEC PCopyTable 'TStockInDetail','cd236.KunMing_YongSheng.dbo.TStockInDetail',' ' --出库单 EXEC PCopyTable 'TStockOutBill','cd236.KunMing_YongSheng.dbo.TStockOutBill',' ' EXEC PCopyTable 'TStockOutDetail','cd236.KunMing_YongSheng.dbo.TStockOutDetail',' ' EXEC PCopyTable 'TStockOutDetailBatch','cd236.KunMing_YongSheng.dbo.TStockOutDetailBatch',' ' --盘点 EXEC PCopyTable 'TTakeStockBill','cd236.KunMing_YongSheng.dbo.TTakeStockBill',' ' EXEC PCopyTable 'TTakeStockDetail','cd236.KunMing_YongSheng.dbo.TTakeStockDetail',' ' EXEC PCopyTable 'TTakeStockDetailBatch','cd236.KunMing_YongSheng.dbo.TTakeStockDetailBatch',' ' PChangeCenterCompany '000' pcOPYTABLE 'TBizLog','cd236.KunMing_YongSheng.dbo.TBizLog','' DECLARE @Sql VARCHAR(MAX) SET @SQL = '' SELECT @SQL = @SQL + name + ',' FROM syscolumns WHERE id = object_id('TBizLogIndex') print @sql ALTER TABLE TBizLog ADD FOldId INT INSERT TBizLog(FOldId,FTime,FCompId,FCompNo,FUserId,FUserNo,FUserName,FFunction,FOperation,FDescription,FContentType,FContent,FIPAddress,FMachineCode,FVersion) SELECT FId,FTime,FCompId,FCompNo,FUserId,FUserNo,FUserName,FFunction,FOperation,FDescription,FContentType,FContent,FIPAddress,FMachineCode,FVersion FROM cd236.KunMing_YongSheng.dbo.TBizLog WHERE FCompId IN(SELECT FCompId FROM #Company) INSERT TBizLogIndex(FLogId,FKey,FValue) SELECT A.FId,B.FKey,B.FValue FROM TBizLog AS A,cd236.KunMing_YongSheng.dbo.TBizLogIndex AS B WHERE A.FOldId = B.FLogId pcOPYTABLE 'TBizLogIndex','cd236.KunMing_YongSheng.dbo.TBizLogIndex','' ALTER TABLE [cd236.KunMing_YongSheng.dbo.TBizLog] ADD FOldId INT SELECT MAX(FId ) FROM TBizLog SELECT * FROM TMemberCardTypeCross DELETE TMemberCardTypeCross SELECT * FROM cd236.KunMing_YongSheng..TWeChatAppInfo SELECT *INTO _wechatAppInfo FROM TWeChatAppInfo SELECT *INTO _wechatAppConfig FROM TWeChatAppConfig DELETE twechatAppInfo PCopyTable 'TwechatAppInfo','cd236.KunMing_YongSheng.dbo.TwechatAppInfo',' ' PDropColumn twechatAppInfo, FAliPayAppId select *from --删除 UPDATE TMemberCard SET FDeleted = 1,FCardnO = FCardNo + '【0532HeChen删除】',FMemo = FMemo + '【0532HeChen删除】' WHERE FCardId IN(SELECT FCardId FROM #MemberCardD) AND FDeleted = 0 AND FMemID > 0 UPDATE TMemberCourse SET FDeleted = 1,FMemo = FMemo + '【0532HeChen删除】' WHERE FId NOT IN(SELECT FId FROM #MemberCourseD) AND FDeleted = 0 AND FMemID > 0 --删除 UPDATE TMember SET FDeleted = 1,FMemNo = FMemNo + '【0532HeChen删除】',FMemo = FMemo + '【0532HeChen删除】' WHERE FCompId NOT IN(SELECT FCompId FROM #Company) AND FMemID NOT IN(SELECT FMemId FROM TMemberCard WHERE FDeleted = 0) AND FMemID NOT IN(SELECT FMemId FROM TMemberCourse WHERE FDeleted = 0) AND FMemId IN(SELECT FMemId FROM #MemberCardD UNION ALL SELECT FMemId FROM #MemberCourseD) AND FMemID > 0 AND FDeleted = 0 --老店 --删除 UPDATE cd236.KunMing_YongSheng.dbo.TMemberCard SET FDeleted = 1,FCardnO = FCardNo + '【0532HuaLi删除】',FMemo = FMemo + '【0532HuaLi删除】' WHERE FCardId IN(SELECT FCardId FROM #membercard) AND FDeleted = 0 UPDATE cd236.KunMing_YongSheng.dbo.TMemberCourse SET FDeleted = 1,FMemo = FMemo + '【0532HuaLi删除】' WHERE FId IN(SELECT FId FROM #memberCourse) AND FDeleted = 0 --删除 UPDATE cd236.KunMing_YongSheng.dbo.TMember SET FDeleted = 1,FMemNo = FMemNo + '【0532HuaLi删除】',FMemo = FMemo + '【0532HuaLi删除】' WHERE FCompId IN(SELECT FCompId FROM #Company) AND FMemID NOT IN(SELECT FMemId FROM cd236.KunMing_YongSheng.dbo.TMemberCard WHERE FDeleted = 0) AND FMemID NOT IN(SELECT FMemId FROM cd236.KunMing_YongSheng.dbo.TMemberCourse WHERE FDeleted = 0) AND FDeleted = 0 AND FMemId IN(SELECT FMemId FROM #MemberCard UNION ALL SELECT FMemId FROM #MemberCourse) UPDATE A SET A.FMemNO = B.FMemNo FROM TConsumeBill AS A,TMember AS B WHERE A.FMemId = B.FMemId AND A.FMemId> 0 AND B.FDeleted = 1 UPDATE A SET A.FCardNO = B.FCardNO FROM TConsumeBill AS A,TMemberCard AS B WHERE A.FCardId = B.FCardId AND A.FMemId> 0 AND B.FDeleted = 1 UPDATE A SET A.FMemNo = B.FMemNo FROM TMemberSaleBill AS A,TMember AS B WHERE A.FMemId = B.FMemId AND A.FMemId> 0 AND B.FDeleted = 1 UPDATE A SET A.FPayCardno = B.FCardno FROM TMemberSaleBill AS A,TMemberCard AS B WHERE A.FPayCardId = B.FCardId AND A.FPayCardId> 0 AND B.FDeleted = 1 UPDATE A SET A.FMemNO = B.FMemNo FROM cd236.KunMing_YongSheng..TConsumeBill AS A,cd236.KunMing_YongSheng..TMember AS B WHERE A.FMemId = B.FMemId AND A.FMemId> 0 AND B.FDeleted = 1 UPDATE A SET A.FCardNO = B.FCardNO FROM cd236.KunMing_YongSheng.dbo.TConsumeBill AS A,cd236.KunMing_YongSheng..TMemberCard AS B WHERE A.FCardId = B.FCardId AND A.FMemId> 0 AND B.FDeleted = 1 UPDATE A SET A.FMemNo = B.FMemNo FROM cq193.KunMing_DongNi..TMemberSaleBill AS A,cq193.KunMing_DongNi..TMember AS B WHERE A.FMemId = B.FMemId AND A.FMemId> 0 AND B.FDeleted = 1 UPDATE A SET A.FPayCardno = B.FCardno FROM cq193.KunMing_DongNi..TMemberSaleBill AS A,cq193.KunMing_DongNi..TMemberCard AS B WHERE A.FPayCardId = B.FCardId AND A.FPayCardId> 0 AND B.FDeleted = 1