use JiNan_KaiKouXiao SELECT * FROM qd177.JiNan_TeFuSuoBi.dbo.TCompany SELECT * FROM TPayAccount drop table #acct CREATE TABLE #AcctMap ( FEmpId BIGINT, FOldAcctId BIGINT, FNewAcctId BIGINT ) insert #AcctMap SELECT B.FId AS FEmpId,3 AS FOldAcctId,A.FId as FNewAcctId FROM TPayAccount AS A,qd177.JiNan_TeFuSuoBi.dbo.TEmployee AS B WHERE B.FNo = '002' AND A.FNo IN('40') insert #AcctMap SELECT B.FId AS FEmpId,10 AS FOldAcctId, A.FId AS FNewAcctId FROM TPayAccount AS A,qd177.JiNan_TeFuSuoBi.dbo.TEmployee AS B WHERE B.FNo = '002' AND A.FNo IN('41') insert #AcctMap SELECT B.FId AS FEmpId,3 AS FOldAcctId, A.FId AS FNewAcctId FROM TPayAccount AS A,qd177.JiNan_TeFuSuoBi.dbo.TEmployee AS B WHERE B.FNo = '003' AND A.FNo IN('42') insert #AcctMap SELECT B.FId AS FEmpId,10 AS FOldAcctId, A.FId AS FNewAcctId FROM TPayAccount AS A,qd177.JiNan_TeFuSuoBi.dbo.TEmployee AS B WHERE B.FNo = '003' AND A.FNo IN('43') use qingdao_shiqi SELECT * FROM qd177.JiNan_TeFuSuoBi.dbo.TCompany CREATE TABLE #Company ( FCompId BIGINT ) INSERT #Company SELECT fiD FROM qd177.JiNan_TeFuSuoBi.DBO.TCompany WHERE FNo IN('012') --门店 SELECT * INTO #Comp FROM qd177.JiNan_TeFuSuoBi.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','qd177.JiNan_TeFuSuoBi.dbo.TAccessDict',' AND FKey NOT IN(SELECT FKey FROM TAccessDict)' SELECT *INTO #User FROM qd177.JiNan_TeFuSuoBi.dbo.TUser WHERE 1=1 AND FId IN(SELECT FUserId FROM qd177.JiNan_TeFuSuoBi.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','qd177.JiNan_TeFuSuoBi.dbo.TRole','AND FId not in(SELECT FId FROM TRole) AND FId IN(SELECT FRoleId FROM qd177.JiNan_TeFuSuoBi.dbo.TUserRole WHERE FUserId IN(SELECT FId FROM TUser))' EXEC PCopyTable 'TUserRole','qd177.JiNan_TeFuSuoBi.dbo.TUserRole','AND FId NOT IN(SELECT FId FROM TUserRole) AND FUserId IN(SELECT FId FROM TUser) ' EXEC PCopyTable 'TRoleAccess','qd177.JiNan_TeFuSuoBi.dbo.TRoleAccess','AND FRoleId NOT IN(SELECT FRoleId FROM TRoleAccess) AND FRoleId IN(SELECT FId FROM TRole) ' EXEC PCopyTable 'TUserAllowCompany','qd177.JiNan_TeFuSuoBi.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 * FROM #AcctMap --会员 SELECT * INTO #MemberCardI FROM qd177.JiNan_TeFuSuoBi.dbo.TMemberCard WHERE FBizEmpId IN(SELECT FEmpId FROM #AcctMap) --AND FTypeId IN(SELECT FId FROM TMemberCardType WHERE FNo IN('001','208','202','203','204','207','206','205','210','209')) SELECT * INTO #MemberCourseI FROM qd177.JiNan_TeFuSuoBi.dbo.TMemberCourse WHERE FBizEmpId IN(SELECT FEmpId FROM #AcctMap) --AND FPurchaseDate < '2019-08-04' --跨点的会员,需要删除 SELECT * INTO #MemberCardD FROM qd177.JiNan_TeFuSuoBi.dbo.TMemberCard WHERE FCardId NOT IN(SELECT FCardId FROM #MemberCardI) AND (FCardId IN(SELECT A.FCardId FROM qd177.JiNan_TeFuSuoBi.DBO.TConsumeBill AS B,qd177.JiNan_TeFuSuoBi.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 qd177.JiNan_TeFuSuoBi.DBO.TConsumeBill AS B,qd177.JiNan_TeFuSuoBi.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 qd177.JiNan_TeFuSuoBi.dbo.TMemberCourse WHERE FId NOT IN(SELECT FId FROM #MemberCourseI) AND (FId IN(SELECT A.FMemCourseId FROM qd177.JiNan_TeFuSuoBi.DBO.TConsumeBill AS B,qd177.JiNan_TeFuSuoBi.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 qd177.JiNan_TeFuSuoBi.dbo.TMember WHERE FMemId IN( SELECT FMemID FROM #MemberCard UNION ALL SELECT FMemId FROM #MemberCourse GROUP BY FMemId ) --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 ,FMemberDisplay) SELECT FId,FNo,FName,FDescription,FIsAccount,FAllowEdit,FItemBizRate,FGoodsBizRate,FCardBizRate,FItemPerfRate,FGoodsPerfRate,FCardPerfRate,FItemPointRate,FGoodsPointRate,FCardPointRate,FIsCashIncome,FIsBizIncome,FIsCashPerf,FIsLabor,FCourseIsLabor,FEnabled,FOrder ,FMemberDisplay FROM qd177.JiNan_TeFuSuoBi.dbo.TPayAccount WHERE 1=1 AND FId NOT IN(SELECT FId FROM TPayAccount) and FId IN(SELECT A.FAcctId FROM qd177.JiNan_TeFuSuoBi.dbo.TMemberCardAccount AS A WHERE A.FCardId In(select fcardid from #Membercard)) SELECT a.FPayTypeId FROM qd177.JiNan_TeFuSuoBi.dbo.TConsumeItemPayment AS A,qd177.JiNan_TeFuSuoBi.dbo.TConsumeBill AS B,#Company AS C WHERE B.FBillId = A.FBillId AND B.FCompId = C.FCompId UNION ALL SELECT a.FPayTypeId FROM qd177.JiNan_TeFuSuoBi.dbo.TConsumeGoodsPayment AS A,qd177.JiNan_TeFuSuoBi.dbo.TConsumeBill AS B,#Company AS C WHERE B.FBillId = A.FBillId AND B.FCompId = C.FCompId UNION ALL SELECT a.FPayTypeId FROM qd177.JiNan_TeFuSuoBi.dbo.TMemberSalePayment AS A,qd177.JiNan_TeFuSuoBi.dbo.TMemberSaleBill AS B,#Company AS C WHERE B.FBillId = A.FBillId AND B.FCompId = C.FCompId ) EXEC PDropColumn 'TPayAccount','FBKAcctId' EXEC PDropColumn 'TPayAccount','FBKPayNo' UPDATE #PayAccount SET FNo = 'FH' + FNo WHERE FId NOT IN(SELECT FId FROM TPayAccount) AND FNo IN(SELECT FNo FROM TPayAccount) UPDATE EXEC PCopyTable 'TPayAccount','#PayAccount',' ' --基本类别 --产品单位,项目类别,折扣类别, SELECT * INTO #Unit FROM TBasicType WHERE FKey like 'GoodsUnit' AND FId NOT IN(SELECT FUnitId FROM TGoods ) --储值卡类别 drop table #MemberCardType select fitemid from #membercourse SELECT * FROM TMemberCardType select * from #MemberCardType where fid in(select fid from TMemberCardType) drop table #MemberCardType SELECT * INTO #MemberCardType FROM qd177.JiNan_TeFuSuoBi.dbo.TMemberCardType WHERE FId > 10 AND FId IN(SELECT FTypeId FROM #MemberCard ) UPDATE #MemberCardType SET FNo = 'sftb' + FNo WHERE FNo not like 'AN%' WHERE FNo IN(SELECT FNo FROM TMemberCardType) EXEC PCopyTable 'TMemberCardType','#MemberCardType',' AaND FId NOT IN(SELECT FId FROM TMemberCardType)' SELECT * FROM #MemberCardType WHERE FId IN(SELECT FId FROM TMemberCardType) drop table #MemberCardType SELECT A.FBizEmpId,A.FNewCardTypeId,B.* INTO #MemberCardType FROM qd177.JiNan_TeFuSuoBi.dbo.TMemberCardType AS B,( select FTypeId,FBizEmpId,dbo.FNNewId() AS FNewCardTypeId FROM #MemberCard GROUP BY FBizEmpId,FTypeId) AS A WHERE A.FTypeId = B.FId UPDATE #MemberCardType SET FNo = '【特浮索彼宇皓】' + FNo,FName = '【特浮索彼宇皓】' + FName WHERE FBizEmpID = (SELECT FId FROM qd177.JiNan_TeFuSuoBi.dbo.TEmployee WHERE FNo = '002') UPDATE #MemberCardType SET FNo = '【特浮索彼王龙】' + FNo,FName = '【特浮索彼王龙】' + FName WHERE FBizEmpID = (SELECT FId FROM qd177.JiNan_TeFuSuoBi.dbo.TEmployee WHERE FNo = '003') INSERT TMemberCardType(FId,FNo,FName,FValueType,FMaterial,FPrice,FCardFeeAmt,FAcctId,FDeposit,FAcctId2,FDeposit2,FAcctId3,FDeposit3,FTimes,FAlertBalance,FMinRchgAmt,FMinSaleAmt,FSalePointMode,FSalePointValue,FRchgPointMode,FRchgPointValue,FPaySmsFee,FTimeCard,FValidityPeriod,FValidityPeriodUnit,FExpiredDate,FDefaultMemo,FCreateTime,FAllowSale,FAllowRchg,FAllowUpgrade,FDeptId,FEnabled,FNeedPush,FNeedPushTimes,FNeedPushExpired,FPopupRemindExpiredDays,FDisplay,FLevel,FOrder,FDeleted,FSaleMaxArrear,FRchgMaxArrear,FRetainRate,FNewMemberOnly) SELECT FNewCardTypeId,FNo,FName,FValueType,FMaterial,FPrice,FCardFeeAmt,FAcctId,FDeposit,FAcctId2,FDeposit2,FAcctId3,FDeposit3,FTimes,FAlertBalance,FMinRchgAmt,FMinSaleAmt,FSalePointMode,FSalePointValue,FRchgPointMode,FRchgPointValue,FPaySmsFee,FTimeCard,FValidityPeriod,FValidityPeriodUnit,FExpiredDate,FDefaultMemo,FCreateTime,FAllowSale,FAllowRchg,FAllowUpgrade,FDeptId,FEnabled,FNeedPush,FNeedPushTimes,FNeedPushExpired,FPopupRemindExpiredDays,FDisplay,FLevel,FOrder,FDeleted,FSaleMaxArrear,FRchgMaxArrear,FRetainRate,FNewMemberOnly FROM #MemberCardType WHERE 1=1 UPDATE A SET A.FTypeId = B.FNewCardTypeId FROM #MemberCard AS A,#MemberCardType AS B WHERE A.FTypeId = B.FId AND A.FBizEmpId = B.FBizEmpId INSERT INTO TMemberCardTypeSub(FId,FCompId,FCardTypeId,FAllowSale,FAllowRchg,FEnabled) SELECT dbo.FNNewId(),C.FId,I.FId,FAllowSale,FAllowRchg,FEnabled FROM TMemberCardType AS I,TCompany AS C WHERE I.FId > 1 AND C.FId != 0 -- AND C.FNo = '009' AND I.FId IN(SELECT FNewCardTypeId FROM #MemberCardType) SELECT * INTO #MemberCardTypeSub FROM qd177.JiNan_TeFuSuoBi.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',' AND CAST(FCompId AS VARCHAR) + CAST(FCardTypeId AS VARCHAR) NOT IN(SELECT CAST(FCompId AS VARCHAR) + CAST(FCardTypeId AS VARCHAR) FROM TMemberCardTYPESUB)' SELECT * FROM # --项目 drop table #Item SELECT B.FBizEmpId,B.FNewCourseId,B.FNewItemId, A.* INTO #Item FROM qd177.JiNan_TeFuSuoBi.dbo.TItem AS A,( select FItemId AS FItemId,FCourseId AS FCourseId,dbo.FNNewId() AS FNewItemId ,dbo.FNNewId() AS FNewCourseId ,FBizEmpId FROM #MemberCourse GROUP BY FBizEmpId,FItemId,FCourseId ) AS B WHERE B.FItemId = A.FId select *from #Item UPDATE #Item SET FNo = '【特浮索彼宇皓】' + FNo,FName = '【特浮索彼宇皓】' + FName WHERE FBizEmpID = (SELECT FId FROM qd177.JiNan_TeFuSuoBi.dbo.TEmployee WHERE FNo = '002') UPDATE #Item SET FNo = '【特浮索彼王龙】' + FNo,FName = '【特浮索彼王龙】' + FName WHERE FBizEmpID = (SELECT FId FROM qd177.JiNan_TeFuSuoBi.dbo.TEmployee WHERE FNo = '003') INSERT TItem(FId,FNo,FNoOfPad,FName,FAbbr,FTypeId,FBriefCode,FDescription,FPriceMode,FIsService,FStatTimes,FCustom1,FCustom2,FCustom3,FEnabled,FPrice,FVipPrice,FTime,FDctId,FDisplayTypeId,FBrandId,FPointMode,FPointValue,FDeptId,FAllowBooking,FDisplay,FHidden,FDeleted,FIsOnline,FImages) SELECT FNewItemId,FNo,FNoOfPad,FName,FAbbr,FTypeId,FBriefCode,FDescription,FPriceMode,FIsService,FStatTimes,FCustom1,FCustom2,FCustom3,FEnabled,FPrice,FVipPrice,FTime,FDctId,FDisplayTypeId,FBrandId,FPointMode,FPointValue,FDeptId,FAllowBooking,FDisplay,FHidden,FDeleted,FIsOnline,FImages FROM #Item drop table #Course INSERT INTO TCourse(FId,FNo,FName,FBriefCode,FItemId,FPackId,FSequence,FTypeId,FTimes,FFreeTimes,FDurable,FValidityPeriodUnit,FValidityPeriod,FCreateDate,FExpiredDate,FDescription,FEnabled,FPrice,FAmount,FCalcMode) SELECT FNewCourseId AS FId, I.FNo , I.FName, '' AS FBriefCode, I.FNewItemId AS FItemId, 0 AS FPackId, 1 AS FSequence, (SELECT TOP 1 FId FROM TBasicType WHERE FKey = 'CourseType') AS FTypeId, 1 AS FTimes, 0 AS FFreeTimes, 0 AS FDurable, 0 AS FValidityPeriodUnit, 0 AS FValidityPeriod, getdate() AS FCreateDate, NULL AS FExpiredDate, '' AS FDescription, 1 AS FEnabled, 0 AS FPrice, 0 AS FAmount, 1 AS FCalcMode FROM #Item AS I UPDATE A SET A.FItemId = B.FNewItemId, A.FCourseId = B.FNewCourseId FROM #MemberCourse AS A,#Item AS B WHERE A.FItemId = B.FId --产品 SELECT *into #Goods FROM qd177.JiNan_TeFuSuoBi.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','qd177.JiNan_TeFuSuoBi.dbo.TGoodsSub',' AND FId > 0 AND FCompId IN(SELECT 1 UNION ALL SELECT FCompId FROM #Company)' EXEC PCopyTable 'TGoodsMultiUnit','qd177.JiNan_TeFuSuoBi.dbo.TGoodsMultiUnit',' AND FId > 0 ' --员工 SELECT * INTO #Employee FROM qd177.JiNan_TeFuSuoBi.dbo.TEmployee where 1=1 AND FId IN(SELECT FEmpId FROM qd177.JiNan_TeFuSuoBi.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 'TBasicDataSyncControl','qd177.JiNan_TeFuSuoBi.dbo.TBasicDataSyncControl','' EXEC PInitBasicDataSyncControl UPDATE #Member SET FMemNO = 'TFSB' + FMemNO WHERE FMemNO IN(SELECT FMemNO FROM TMember) OR FMemNo IN(SELECT FCardNo FROM TMemberCard) UPDATE #MemberCard SET FCardNo = 'TFSB' + 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) UPDATE TMember SET 'S' =FMemNo WHERE FM 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','qd177.JiNan_TeFuSuoBi.dbo.TMemberCardAccount',' AND FCardId IN(SELECT FCardId FROM #MemberCard) ' EXEC PCopyTable 'TMemberCardAcctHist','qd177.JiNan_TeFuSuoBi.dbo.TMemberCardAcctHist',' AND FCardId IN(SELECT FCardId FROM #MemberCard) ' SELECT * FROM #MemberCourse WHERE FMemId NOT IN(SELECT FMemId FROM TMember) EXEC PCopyTable 'TMemberCoursePack','qd177.JiNan_TeFuSuoBi.dbo.TMemberCoursePack',' AND FId IN(SELECT FId FROM #MemberPack)' EXEC PCopyTable 'TMemberGoods','qd177.JiNan_TeFuSuoBi.dbo.TMemberGoods',' AND FMemId IN(SELECT FMemId FROM #Member)' EXEC PCopyTable 'TMemberCourse','#MemberCourse',' AND FId IN(SELECT FId FROM #MemberCourse) ' EXEC PCopyTable 'TMemberCourseLog','qd177.JiNan_TeFuSuoBi.dbo.TMemberCourseLog',' AND FCardId IN(SELECT FId FROM #MemberCourse) ' EXEC PCopyTable 'TMemberEmployee','qd177.JiNan_TeFuSuoBi.dbo.TMemberEmployee',' AND FMemId IN(SELECT FMemId FROM #Member) ' EXEC PCopyTable 'TMemberPhoto','qd177.JiNan_TeFuSuoBi.dbo.TMemberPhoto',' AND FMemId IN(SELECT FMemId FROM #Member) ' EXEC PCopyTable 'TMemberPointHist','qd177.JiNan_TeFuSuoBi.dbo.TMemberPointHist',' AND FMemId IN(SELECT FMemId FROM #Member)' EXEC PCopyTable 'TMemberTransHist','qd177.JiNan_TeFuSuoBi.dbo.TMemberTransHist',' AND FMemId IN(SELECT FMemId FROM #Member) ' EXEC PCopyTable 'TMemberTransHistPayment','qd177.JiNan_TeFuSuoBi.dbo.TMemberTransHistPayment','AND FMemId IN(SELECT FMemId FROM #Member) ' EXEC PCopyTable 'TMemberOldTransHist','qd177.JiNan_TeFuSuoBi.dbo.TMemberOldTransHist',' AND FMemId IN(SELECT FMemId FROM #Member) ' EXEC PCopyTable 'TMemberCardOldAcctHist','qd177.JiNan_TeFuSuoBi.dbo.TMemberCardOldAcctHist',' AND FMemId IN(SELECT FMemId FROM #Member) ' EXEC PCopyTable 'TMemberArrear','qd177.JiNan_TeFuSuoBi.dbo.TMemberArrear',' AND FMemId IN(SELECT FMemId FROM #Member) ' EXEC PCopyTable 'TMemberRepay','qd177.JiNan_TeFuSuoBi.dbo.TMemberRepay',' AND FMemId IN(SELECT FMemId FROM #Member) ' EXEC PCopyTable 'TMemberArrearEmployee','qd177.JiNan_TeFuSuoBi.dbo.TMemberArrearEmployee',' AND FMemId IN(SELECT FMemId FROM #Member) ' SELECT *into #Pay FROM qd177.JiNan_TeFuSuoBi.dbo. TPayAccount WHERE FId IN(SELECT FAcctId FROM TMemberCardAccount WHERE FCardId in(select fCARDID FROM #MemberCard)) AND FId = 4698091532626680320 UPDATE #Pay SET FNo = 'Tfsb' + FNo PCopyTable 'TPayAccount','#Pay','' UPDATE A SET A.FAcctId = B.FNewAcctId FROM TMemberCardAccount AS A,TMemberCard AS C,#AcctMap B WHERE C.FCardId = A.FCardId AND A.FaCCTId = B.FOldAcctId AND C.FBizEmpId = B.FEmpId UPDATE A SET A.FAcctId = B.FNewAcctId FROM TMemberCardAcctHist AS A,TMemberCard AS C,#AcctMap B WHERE C.FCardId = A.FCardId AND A.FaCCTId = B.FOldAcctId AND C.FBizEmpId = B.FEmpId UPDATE A SET A.FCardTypeId = B.FTypeId FROM TMemberCardAcctHist AS A,#MemberCard AS B WHERE A.FCardId = B.FCardId UPDATE A SET A.FPayTYPEId= B.FNewAcctId FROM TMemberTransHistPayment AS A,TMemberCard AS C,#AcctMap B WHERE C.FCardId = A.FCardId AND A.FPayTYPEId = B.FOldAcctId AND C.FBizEmpId = B.FEmpId UPDATE A SET A.FItemId = B.FItemId FROM TMemberCourseLog AS A,#MEMBERCOURSE AS B WHERE A.FCardID = B.FID --老店 --删除 UPDATE qd177.JiNan_TeFuSuoBi.dbo.TMemberCard SET FDeleted = 1,FCardnO = FCardNo + '【0531kkx删除】',FMemo = FMemo + '【0531kkx删除】' WHERE FCardId IN(SELECT FCardId FROM #membercard) AND FDeleted = 0 UPDATE qd177.JiNan_TeFuSuoBi.dbo.TMemberCourse SET FDeleted = 1,FMemo = FMemo + '【0531kkx删除】' WHERE FId IN(SELECT FId FROM #memberCourse) AND FDeleted = 0 --删除 UPDATE qd177.JiNan_TeFuSuoBi.dbo.TMember SET FDeleted = 1,FMemNo = FMemNo + '【0531kkx删除】',FMemo = FMemo + '【0531kkx删除】' WHERE 1=1 AND FMemID NOT IN(SELECT FMemId FROM qd177.JiNan_TeFuSuoBi.dbo.TMemberCard WHERE FDeleted = 0) AND FMemID NOT IN(SELECT FMemId FROM qd177.JiNan_TeFuSuoBi.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 qd177.JiNan_TeFuSuoBi.dbo.TConsumeBill AS A,qd177.JiNan_TeFuSuoBi.dbo.TMember AS B WHERE A.FMemId = B.FMemId AND A.FMemId> 0 AND B.FDeleted = 1 UPDATE A SET A.FCardNO = B.FCardNO FROM qd177.JiNan_TeFuSuoBi.dbo.TConsumeBill AS A,qd177.JiNan_TeFuSuoBi.dbo.TMemberCard AS B WHERE A.FCardId = B.FCardId AND A.FMemId> 0 AND B.FDeleted = 1 UPDATE A SET A.FMemNo = B.FMemNo FROM qd177.JiNan_TeFuSuoBi.dbo.TMemberSaleBill AS A,qd177.JiNan_TeFuSuoBi.dbo.TMember AS B WHERE A.FMemId = B.FMemId AND A.FMemId> 0 AND B.FDeleted = 1 UPDATE A SET A.FPayCardno = B.FCardno FROM qd177.JiNan_TeFuSuoBi.dbo.TMemberSaleBill AS A,qd177.JiNan_TeFuSuoBi.dbo.TMemberCard AS B WHERE A.FPayCardId = B.FCardId AND A.FPayCardId> 0 AND B.FDeleted = 1