use zoucheng_tt SELECT * FROM TImp SELECT * FROM TImpMemberCard --卡类别 SELECT * FROM TImpCardType ALTER TABLE TImpCardType ADD FCardTypeId BIGINT ALTER TABLE TImpCardType ADD FCardTypeNo VARCHAR(50) ALTER TABLE TImpCardType ADD FCardTypeName VARCHAR(50) UPDATE TImpCardType SET FCardTypeId = CardCategoryId, FCardTypeName = CardCategoryName, FCardTypeNo = HotKey sp_rename 'TImpCardType.FId','FCardTypeId' INSERT INTO TMemberCardType(FId,FNo,FName,FValueType,FMaterial,FPrice,FCardFeeAmt,FAcctId,FDeposit,FAcctId2,FDeposit2,FAcctId3,FDeposit3,FTimes,FAlertBalance,FMinRchgAmt,FSalePointMode,FSalePointValue,FRchgPointMode,FRchgPointValue,FPaySmsFee,FTimeCard,FValidityPeriod,FValidityPeriodUnit,FExpiredDate,FDefaultMemo,FCreateTime,FAllowSale,FAllowRchg,FDeptId,FEnabled,FOrder) SELECT FId =FCardTypeId, FCardTypeNo,FCardTypeName,1,FMaterial = 2,Price,FCardFeeAmt = 0,FAcctId = 3,FDeposit = StoredValue,FAcctId2 = 0,FDeposit2 = 0 ,FAcctId3 = 0,FDeposit3 = 0, FTimes = 0,FAlertBalance = 0,FMinRchgAmt = 0,FSalePointMode = 0,FSalePointValue = 0 ,FRchgPointMode = 0,FRchgPointValue = 0,FPaySmsFee = 0,FTimeCard = 0,FValidityPeriod = 100,FValidityPeriodUnit = 1, FExpiredDate = NULL,FDefaultMemo = '',FCreateTime = GETDATE(),1,1,FDeptId = 0,FEnabled =1,FOrder = 1 FROM TImpCardType INSERT INTO TMemberCardTypeSub(FId,FCompId,FCardTypeId,FAllowSale,FAllowRchg,FEnabled) SELECT dbo.FNNewId(),dbo.FNCompId('001'),I.FCardTypeId,1,1,1 FROM TImpCardType AS I SELECT * FROM TImpMember AS A,TImpMemberCard AS B WHERE A.FNo = B.FCLientNO AND A.FName = '' AND FMoney > 0 SELECT * FROM TImpMember SELECT * FROM TImpMemberCard SELECT * FROM TImpMemberCard WHERE FClientNO = '0003' ALTER TABLE TImpMemberCard ADD FCardTypeName VARCHAR(100) ALTER TABLE TImpMemberCard ADD FMemId BIGINT ALTER TABLE TImpMemberCard ADD FCardNo VARCHAR(50) ALTER TABLE TImpMemberCard ADD FCardState INT ALTER TABLE TImpMemberCard ADD FCardTypeId BIGINT ALTER TABLE TImpMemberCard ADD FBalance DECIMAL(18,6) ALTER TABLE TImpMemberCard ADD FBalance2 DECIMAL(18,6) ALTER TABLE TImpMemberCard ADD FRemainTimes INT ALTER TABLE TImpMemberCard ADD FCreateDate DATETIME ALTER TABLE TImpMemberCard ADD FExpiredDate DATETIME ALTER TABLE TImpMemberCard ADD FMemo VARCHAR(1000) ALTER TABLE TImpMemberCard ADD FCompId BIGINT ALTER TABLE TImpMemberCard ADD FCardId BIGINT ALTER TABLE TImpMember ADD FCompId BIGINT ALTER TABLE TImpMember ADD FMemId BIGINT ALTER TABLE TImpMember ADD FMemNo VARCHAR(50) ALTER TABLE TImpMember ADD FName VARCHAR(50) ALTER TABLE TImpMember ADD FGender INT ALTER TABLE TImpMember ADD FMobile VARCHAR(50) ALTER TABLE TImpMember ADD FMemo VARCHAR(1000) ALTER TABLE TImpMember ADD FArrear DECIMAL(18,6) ALTER TABLE TImpMember ADD FPoint DECIMAL(18,6) ALTER TABLE TImpMember ADD FState INT ALTER TABLE TImpMember ADD FCreateDate DATETIME ALTER TABLE TImpMember ADD FDeleted BIT ALTER TABLE TImpMember ADD FBirthday DATETIME ALTER TABLE TImpMember ADD FBirthdayType CHAR --会员ID UPDATE TImpMember SET FMemId=MemberId --卡ID UPDATE TImpMemberCard SET FCardId=MCID --卡会员ID UPDATE A SET A.FMemId = B.FMemId FROM TImpMember AS B,TImpMemberCard AS A WHERE A.MemberShopId = B.MemberShopId --手机号码,姓名,性别,生日,积分 UPDATE TImpMember SET FName = TrueName,FMobile = Mobile,FGender = Sex , FBirthdayType = CASE WHEN BirthdayType = 2 THEN 'G' ELSE 'L' END, FBirthday = BirthdayText, FCreateDate = CreateTime, FPoint = WebPoints UPDATE TImpMember SET FBirthday = NULL WHERE FBirthday = '1900-01-01 00:00:00.000' --门店 UPDATE TImpMember SET FCompId = 1 --储值卡号 --select * from TImpMemberCard UPDATE TImpMemberCard SET FCardNo = MemberCardId --会员编号 UPDATE TImpMember SET FMemNo = '' UPDATE A SET A.FMemNo = B.FCardNo FROM TImpMember AS A,TImpMemberCard AS B WHERE A.FMemId = B.FMemId UPDATE TImpMember SET FMemNO = FMobile WHERE ISNULL(FMemNo,'') = '' --把没有卡,又重复的删掉 UPDATE TImpMember SET FDeleted = 0 UPDATE TImpMember SET FDeleted = 1 WHERE MemberShopId NOT IN(SELECT MemberShopId FROM TImpMemberCard) AND MemberShopId NOT IN(SELECT MemberShopId FROM TImpMemberCourse) AND FMemNo IN( SELECT FMemNo FROM TImpMember WHERE FDeleted = 0 GROUP BY FMemNo HAVING(SUM(1) > 1) ) SELECT * FROM TImpMemberCard WHERE FCardTypeID IS NULL SELECT * FROM TImpCardType --卡类别 UPDATE A SET A.FCardTypeID = B.FCarDtYPEiD FROM TImpMemberCard AS A,TImpCardType AS B WHERE REPLACE(A.MemberCardCategoryName,' ','') = REPLACE(B.FCardTypeName,' ','') SELECT * FROM TImpMemberCard WHERE MemberCardCategoryName = 'VIP贵宾卡八折' UPDATE TImpMemberCard SET MemberCardCategoryName = REPLACE(MemberCardCategoryName,'八','8') UPDATE TImpMemberCard SET MemberCardCategoryName = REPLACE(MemberCardCategoryName,'七','7') UPDATE TImpMemberCard SET MemberCardCategoryName = REPLACE(MemberCardCategoryName,'六','6') UPDATE TImpMemberCard SET MemberCardCategoryName = REPLACE(MemberCardCategoryName,'五五','5.5') UPDATE TImpMemberCard SET MemberCardCategoryName = REPLACE(MemberCardCategoryName,'五','5') UPDATE TImpMemberCard SET MemberCardCategoryName = REPLACE(MemberCardCategoryName,'55','5.5') --状态 UPDATE TImpMemberCard SET FCardState = 1 WHERE CardStatusStr = '正常' UPDATE TImpMemberCard SET FCardState = 4 WHERE CardStatusStr = '冻结' SELECT *FROM TImpMemberCard WHERE CardStatusStr != '正常' --余额 UPDATE TImpMemberCard SET FBalance =NowAmount,FBalance2 = NowGiveAmount --有效期 UPDATE TImpMemberCard SET FCreateDate = CreateTimeStr UPDATE TImpMemberCard SET FExpiredDate =ExpiredDateStr WHERE ExpiredDateStr != '无限期' UPDATE TImpMemberCard SET FExpiredDate ='9000-01-01' WHERE ExpiredDateStr = '无限期' UPDATE TImpMemberCard SET FCompId = 1 UPDATE TImpMemberCard SET FSaleCompId = 1 --疗程ID SELECT * FROM TIMpMemberCourse UPDATE TIMpMemberCourse SET FCardId = MCID UPDATE TIMpMemberCourse SET FMemId = MemberId UPDATE TIMpMemberCourse SET FCompId= 1 UPDATE TIMpMemberCourse SET FState = 1 WHERE CardStatusStr = '正常' UPDATE TIMpMemberCourse SET FCourseId = SELECT * FROM TImpMember WHERE FMemId = 3710221 SELECT FMemNo,SUM(1) FROM TImpMember INSERT INTO TMember( FMemId, FMemNo, FName, FBriefCode, FTypeId, FCompId, FCreateDate, FGender, FBirthdayType, FBirthday,FTelephone,FMobilePhone,FQQ,FWeChat,FIdCard,FEmail,FAddress,FProId,FCPW,FQPW, FChargeEmpId,FPoint,FRecvConsSMS,FRecvBulkSMS,FMemo,FCustom1,FCustom2,FCustom3,FCustom4,FCustom5) SELECT FMemId AS FMemId, FMemNo AS FMemNo, FName AS FName, dbo.FNGetFirstPinYin(FName), 0 AS FTypeId, FCompId AS FCompId, FCreateDate AS FCreateDate, FGender AS FGender, FBirthdayType AS FBirthdayType, FBirthday AS FBirthday, '' AS FTelephone, ISNULL(FMobile,'') AS FMobilePhone, '' AS FQQ, '' AS FWeChat, '' AS FIdCard, '' AS FEmail, '' AS FAddress, 0 AS FProId, '' AS FCPW, '' AS FQPW, 0 AS FChargeEmpId, FPoint AS FPoint, 1 AS FRecvConsSMS, 1 AS FRecvBulkSMS, '' AS FMemo, '从老系统导入' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5 from TImpMember WHERE FDeleted = 0 SELECT * FROM TMemberCardType UPDATE A SET A.FId = 0 FROM TImpCardType AS A UPDATE A SET A.FId = B.FId FROM TImpCardType AS A,TMemberCardType AS B WHERE A.FCardTypeNo = B.FNo UPDATE A SET A.FCardTypeId = B.FId FROM TImpMemberCard AS A,TImpCardType AS B WHERE A.FCardTypeId = B.FCardTypeId UPDATE TImpMemberCard SET FCardTypeId = 4953137442972249707 WHERE FCardTypeId = 4960169439336235374 SELECT * FROM TImpCardTyp INSERT INTO TMemberCard( FCardId, FCardNo, FTypeId, FValueType, FCompId, FMemId, FState, FCreateDate, FExpiredDate, FTotalTimes, FUsedTimes, FSaleCompId, FSaleBillId, FMemo) SELECT FCardId AS FId, FCardNo AS FNo, FCardTypeId AS FTypeId, (SELECT FValueType FROM TMemberCardType WHERE FId = FCardTypeId) AS FValueType, FCompId AS FCompId, FMemId AS FMemId, FCardState AS FState, FCreateDate AS FCreateDate, FExpiredDate AS FExpiredDate, 0 AS FTotalTimes, 0 AS FUsedTimes, FCompId AS FSaleCompId, 0 AS FSaleBillId, ISNULL(FMemo,'') AS FMemo FROM TImpMemberCard INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo) SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,3,FBalance,FBalance,0,FCreateDate,NULL AS FExpiredDate,'' FROM TImpMemberCard AS A INSERT TMemberCardAcctHist(FId,FMemId,FCardId,FAcctId,FTime,FCardTypeId,FCompId,FBillType,FBizType,FTransId,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo) select dbo.FNNewId(),A.FMemId,A.FCardId,3,getdate(),A.FCardTypeId,A.FCompId,'DR','Import',0,'',A.FBalance,0,A.FBalance,0,getdate(),'从星沙龙中导入' FROM TImpMemberCard AS A INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo) SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,10,FBalance2,FBalance2,0,FCreateDate,NULL AS FExpiredDate,'' FROM TImpMemberCard AS A WHERE FBalance2 != 0 INSERT TMemberCardAcctHist(FId,FMemId,FCardId,FAcctId,FTime,FCardTypeId,FCompId,FBillType,FBizType,FTransId,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo) select dbo.FNNewId(),A.FMemId,A.FCardId,10,getdate(),A.FCardTypeId,A.FCompId,'DR','Import',0,'',A.FBalance2,0,A.FBalance2,0,getdate(),'从星沙龙中导入' FROM TImpMemberCard AS A WHERE FBalance2 != 0 --疗程 SELECT * FROM TIMpMemberCourse SELECT * FROM TImpMemberCourseDetail ALTER TABLE TIMpMemberCourse ADD FMemId BIGINT ALTER TABLE TIMpMemberCourseDetail ADD FPurTimes INT ALTER TABLE TIMpMemberCourseDetail ADD FUsedPurTimes INT ALTER TABLE TIMpMemberCourseDetail ADD FPurAmount DECIMAL(18,6) ALTER TABLE TIMpMemberCourseDetail ADD FItemId BIGINT ALTER TABLE TIMpMemberCourseDetail ADD FCourseId BIGINT ALTER TABLE TIMpMemberCourseDetail ADD FCreateDate DATETIME ALTER TABLE TIMpMemberCourseDetail ADD FExpiredDate DATETIME ALTER TABLE TIMpMemberCourseDetail ADD FCompId BIGINT ALTER TABLE TIMpMemberCourseDetail ADD FMemId BIGINT ALTER TABLE TIMpMemberCourseDetail ADD FCardId BIGINT UPDATE TImpMemberCourse SET FMemId = MemberId UPDATE A SET A.FMemId = B.FMemId FROM TImpMemberCourseDetail AS A,TImpMemberCourse AS B WHERE A.MCID = B.MCID SELECT * FROM TCourse UPDATE A SET A.FItemId = B.FItemId, A.FCourseId = B.FId FROM TImpMemberCourseDetail AS A,TCourse AS B WHERE A.ServiceItemName = B.FName UPDATE TImpMemberCourseDetail SET FCardId = MCID UPDATE TImpMemberCourseDetail SET FCompId = 1 UPDATE TImpMemberCourseDetail SET FCourseId = 4854799989982317296 UPDATE TImpMemberCourseDetail SET FItemid = 5364344419216701040 UPDATE TImpMemberCourseDetail SET FCreateDate = CreateTimeStr UPDATE TImpMemberCourseDetail SET FExpiredDate = ExpiredDateStr INSERT TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FUsedPurTimes,FPurAmount,FFreeTimes,FFreeAmount,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice) SELECT FCardId,FMemId,FCourseId,0,FItemId,FCompId,ConsumeTimes + 0 + Times + 0,ConsumeTimes,0,0,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,'新沙龙导入',1,0 FROM TImpMemberCourseDetail AS A INSERT INTO TMemberCourseLog(FId,FMemId,FCardId,FPackId,FCourseId,FTime,FInPurTimes,FInFreeTimes,FOutPurTimes,FOutFreeTimes,FCompId,FBillType,FBizType,FBillId,FBillNo,FBillDetailId,FRecordTime) SELECT dbo.FNNewId(),FMemId,A.FCardId AS FCardId,0, ISNULL(FCourseId,0),getdate(),ConsumeTimes + 0 + Times + 0,0,ConsumeTimes,0,FCompId,'DR','Import',0,'',0,getdate() FROM TImpMemberCourseDetail AS A DELETE TMemberCourseLog WHERE FCardId IN(SELECT FCardId FROM TImpMemberCourseDetail) DELETE TMemberCourse WHERE FId IN(SELECT FCardId FROM TImpMemberCourseDetail) SELECT * FROM TCourse DROP TABLE TIMpMemberCourse ALTER TABLE TImpMemberTransHistDetail ADD --教育历史 ALTER TABLE TImpMemberTransHist ADD FCompId BIGINT UPDATE TImpMemberTransHist SET FCompID = 1 INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo) SELECT dbo.FNNewId(),A.MemberId,A.CreateTimeStr,0,A.FCompId,'DR','Import',ConsumeBillNo,ContentStr,0,1,0,Payments,EmployeeNames,'' FROM TImpMemberTransHist AS A ,TImpMemberTransHistDetail AS B WHERE A.Id = B.Id SELECT * FROM TImpMemberTransHist where id = 4911593833057529541 SELECT * FROM TImpMemberTransHistDetail DROP TABLE TImpMemberTransHist DROP TABLE TImpMemberTransHistDetail SELECT Id FROM TImpMemberTransHistDetail GROUP BY ID HAVING(SUM(1) > 1) SELECT * FROM TMember WHERE FMemId= 3709596 1006684 /** 新即兴 13854209915,123456 一泽 18669871559", 123456 时尚范 15726228884 ssf12345678 */