use xian_xianyixin SELECT COUNT(1) FROM TImpMember WHERE phone = '' AND FMobile = '' 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 FCreateDate DATETIME ALTER TABLE TImpMember ADD FCompId BIGINT 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 FBirthday DATETIME ALTER TABLE TImpMember ADD FBirthdayType CHAR ALTER TABLE TImpMemberCard ADD FMemId BIGINT ALTER TABLE TImpMemberCard ADD FCardTypeName VARCHAR(100) ALTER TABLE TImpMemberCard ADD FCardNo VARCHAR(50) ALTER TABLE TImpMemberCard ADD FCardState INT ALTER TABLE TImpMemberCard ADD FMemo VARCHAR(1000) 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 FCompId BIGINT ALTER TABLE TImpMemberCard ADD FCardId BIGINT DROP TABLE TImpCardType GO CREATE TABLE TImpCardType ( FShopId INT , FCardTypeName VARCHAR(500), FCardTypeNo VARCHAR(50), FCardTypeId BIGINT ) DELETE TImpCardType INSERT TImpCardType(FCardTypeId,FCardTypeNo,FCardTypeName) SELECT dbo.FNNewId(), '' + typeName , typeName AS Name FROM TImpMemberCard GROUP BY typeName ORDER BY typeName SELECT * FROM TImpCardType SELECT * FROM TImpMember WHERE FCardTypeName IS NULL WHERE FId NOT IN(SELECT FCardTypeiD FROM TMemberCardTypeSub) AND FId > 11 SELECT * FROM TMemberCardType 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,0,FCardFeeAmt = 0,FAcctId = 3,FDeposit = 0,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 WHERE FCardTypeNo NOT IN(SELECT FNO FROM TMemberCardType) ORDER BY FCardTypeName SELECT * FROM TCompany INSERT INTO TMemberCardTypeSub(FId,FCompId,FCardTypeId,FAllowSale,FAllowRchg,FEnabled) SELECT dbo.FNNewId(),dbo.FNCompId('000'),I.FCardTypeId,1,1,1 FROM TImpCardType AS I 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 storeName FROM TImpMember UPDATE TImpMember SET FMemId = dbo.FNNewId() WHERE FMemId IS NULL UPDATE TImpMember SET FName = Name UPDATE TImpMember SET FMobile = Phone UPDATE TImpMemberCard SET FCompId = dbo.FNCompId('001') where storeName = '蒙自永尚专业美发会所' UPDATE TImpMemberCard SET FCompId = dbo.FNCompId('002') where storeName = '蒙自永尚美业文萃店' UPDATE TImpMember SET FGender = CASE WHEN gender = 'MALE' THEN 1 ELSE 0 END UPDATE TImpMember SET FCreateDate = LEFT(createYmd,4) + '-' + SUBSTRING(createYmd,5,2)+ '-' + SUBSTRING(createYmd,7,2) UPDATE TImpMember SET FMemo = '' UPDATE TImpMemberCard SET FCardno = number UPDATE TImpMemberCard SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL UPDATE TImpMemberCard SET FCompId = dbo.FNCompId('017') UPDATE TImpMemberCard SET FBalance = CAST(CASH AS FLOAT) UPDATE TImpMemberCard SET FBalance2 = CAST(bonus AS FLOAT) UPDATE TImpMemberCard SET FCreateDate = LEFT(createYmd,4) + '-' + SUBSTRING(createYmd,5,2)+ '-' + SUBSTRING(createYmd,7,2) UPDATE TImpMemberCard SET FExpiredDate = LEFT(ExpireYmd,4) + '-' + SUBSTRING(ExpireYmd,5,2)+ '-' + SUBSTRING(ExpireYmd,7,2) WHERE ExpireYmd != '0' UPDATE TImpMemberCard SET FExpiredDate = DATEADD(YEAR,100,FCreateDate) UPDATE TImpMemberCard SET FMemo = remark --卡类别 UPDATE A SET A.FCardTypeId = B.FCardTypeId FROM TImpMemberCard AS A,TImpCardType AS B WHERE A.typeName = B.FCardTypeName UPDATE A SET A.FMemId = B.FMemId FROM TImpMemberCard AS A,TImpMember AS B WHERE A.memberId = B.id UPDATE A SET A.FPoint = B.FPoint FROM TImpMember AS A,( SELECT FMemId,SUM(cast(point as float)) AS FPoint FROM TImpMemberCard GROUP BY FMemId) AS B WHERE A.FMemId = B.FMemId UPDATE TImpMemberCard SET FCardNo = '' + FCardNo WHERE FCardNo IN(SELECT FCardnO FROM TMemberCard) UPDATE TImpMemberCard SET FCardNo = '' + FCardNo WHERE FCardNo IN(SELECT FMemNO FROM TMember) UPDATE A SET A.FMemNo = B.FCardNo FROM TImpMember AS A,TImpMemberCard AS B WHERE A.id = B.MemberId SELECT * FROM TImpMemberCard WHERE status != 'ACTIVE' UPDATE TImpMemberCard SET FCardState = 1 UPDATE TImpMemberCard SET FCardState = 4 WHERE status = 'LOST' --生日 UPDATE TImpMember SET FBirthday = NULL UPDATE TImpMember SET FBirthdayType = 'G' UPDATE TImpMember SET FBirthdayType = 'L' WHERE BirthType = 'SOLAR' --处理疗程 ALTER TABLE TImpMemberCourse ADD FMemId BIGINT ALTER TABLE TImpMemberCourse ADD FCreateDate DATETIME ALTER TABLE TImpMemberCourse ADD FExpiredDate DATETIME ALTER TABLE TImpMemberCourse ADD FItemId BIGINT ALTER TABLE TImpMemberCourse ADD FCardTypeId BIGINT ALTER TABLE TImpMemberCourse ADD FCardId BIGINT ALTER TABLE TImpMemberCourse ADD FCompId BIGINT ALTER TABLE TImpMemberCourse ADD FMemNo BIGINT ALTER TABLE TImpMemberCourse ADD FCardTypeName VARCHAR(100) ALTER TABLE TImpMemberCourse ADD FPurTimes DECIMAL(18,6) ALTER TABLE TImpMemberCourse ADD FUsedPurTimes DECIMAL(18,6) ALTER TABLE TImpMemberCourse ADD FAdjustPrice DECIMAL(18,6) ALTER TABLE TImpMemberCourse ADD FPurAmount DECIMAL(18,6) ALTER TABLE TImpMemberCourse ADD FCardTypeName VARCHAR(100) //疗程名称 UPDATE TImpMemberCourse SET FCardTypeName = serviceName SELECT FCardTypeName FROM TImpMemberCourse GROUP BY FCardTypeName UPDATE A SET A.FMemId = B.FMemId FROM TImpMemberCourse AS A,TImpMember AS B WHERE A.MEMBERID = B.Id CREATE TABLE TImpCourse ( FItemId BIGINT, FCourseId BIGINT, FItemNo VARCHAR(100), FItemName VARCHAR(100) ) INSERT TImpCourse(FItemId,FCourseId,FItemNo,FItemName) SELECT dbo.FNNewId(),dbo.FNNewId(),'HY'+serviceName,serviceName FROM TImpMemberCourse GROUP BY serviceName SELECT * FROM TImpMemberCourse INSERT TItem(FId,FNo,FNoOfPad,FName,FAbbr,FTypeId,FBriefCode,FDescription,FPriceMode,FIsService,FStatTimes,FCustom1,FCustom2,FCustom3,FEnabled,FPrice,FVipPrice,FTime,FDctId,FPointMode,FPointValue,FDeptId,FAllowBooking) SELECT FItemId,FItemNo,FItemNo, FItemName, FItemName,0,dbo.FNGetFirstPinYin(FItemName),'',1,1,1,'','','',1,0,0,0,0,0,0,0,1 FROM TImpCourse INSERT TItemSub(FId,FCompId,FItemId,FPrice,FVipPrice,FTime,FDctId,FPointMode,FPointValue,FDeptId,FAllowBooking,FEnabled) SELECT dbo.FNNewId(),C.FId,I.FId,I.FPrice,I.FVipPrice,I.FTime,I.FDctId,I.FPointMode,I.FPointValue,I.FDeptId,I.FAllowBooking,I.FEnabled FROM TItem AS I,TCompany AS C WHERE I.FId != 0 AND C.FId IN( dbo.FNCompId('001'),dbo.FNCompId('007')) AND NOT EXISTS(SELECT TOP 1 1 FROM TItemSub AS B WHERE B.FCompId = C.FId AND B.FItemId = I.FId) AND I.FId IN(SELECT FItemId FROM TImpCourse) INSERT INTO TCourse(FId,FNo,FName,FBriefCode,FItemId,FPackId,FSequence,FTypeId,FTimes,FFreeTimes,FDurable,FValidityPeriodUnit,FValidityPeriod,FCreateDate,FExpiredDate,FDescription,FEnabled,FPrice,FAmount,FCalcMode) SELECT FCourseId, I.FItemNo + 'L1', I.FItemName , '' AS FBriefCode, I.FItemId AS FItemId, 0 AS FPackId, 1 AS FSequence, 0 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 TImpCourse AS I UPDATE TImpMemberCourse SET FCreateDate = LEFT(createYmd,4) + '-' + SUBSTRING(createYmd,5,2)+ '-' + SUBSTRING(createYmd,7,2) UPDATE TImpMemberCourse SET FCompId = dbo.FNCompId('007') UPDATE A SET A.FCardId = dbo.FNNewId() FROM TImpMemberCourse AS A WHERE A.FCardId IS NULL UPDATE A SET A.FItemId = B.FItemId, A.FCardTypeId = B.FCourseId FROM TImpCourse AS B,TImpMemberCourse AS A WHERE B.FItemName = A.serviceName UPDATE TImpMemberCourse SET FPurTimes = rechargeAmount UPDATE TImpMemberCourse SET FUsedPurTimes = cast(rechargeAmount as float)- cast(remainAmount as float) UPDATE TImpMemberCourse SET FAdjustPrice = price UPDATE TImpMemberCourse SET FPurAmount = cast(rechargeAmount as float) * price UPDATE A SET A.FMemId = B.FMemId FROM TImpMemberCourse AS A,TImpMember AS B WHERE A.memberId = B.id --交易历史 SELECT * FROM TImpMemberLog ALTER TABLE TImpMemberLog ADD FMemId BIGINT ALTER TABLE TImpMemberLog ADD FBillNo VARCHAR(50) ALTER TABLE TImpMemberLog ADD FBizType VARCHAR(50) ALTER TABLE TImpMemberLog ADD FContent VARCHAR(1000) ALTER TABLE TImpMemberLog ADD FAmount DECIMAL(18,6) ALTER TABLE TImpMemberLog ADD FTime DATETIME ALTER TABLE TImpMemberLog ADD FId VARCHAR(50) ALTER TABLE TImpMemberLog ADD FEmployee VARCHAR(1000) ALTER TABLE TImpMemberLog ADD FQuantity DECIMAL(18,6) ALTER TABLE TImpMemberLog ADD FCompId BIGINT UPDATE A SET A.FMemId = M.FMemId FROM TImpMemberLog AS A,TMember AS M WHERE A.会员卡号 = M.FMemNo SELECT * FROM TImpMemberAcctHist UPDATE TImpMemberLog SET FBillNo = 单据号 UPDATE TImpMemberLog SET FContent = 项目名称 UPDATE TImpMemberLog SET FQuantity = 数量 UPDATE TImpMemberLog SET FAmount = 折扣金额 UPDATE TImpMemberLog SET FEmployee = ISNULL(服务员工,'') UPDATE TImpMemberLog SET FTime = 消费日期 UPDATE TImpMemberLog SET FQuantity = 数量 UPDATE TImpMemberLog SET FId = dbo.FNNewId() UPDATE TImpMemberLog SET FCompId = (SELECT FId FROM TCompany WHERE FNo = '003') UPDATE TImpMember SET FMemNO = 'A' + FMemNo,FCardnO = 'A' + FCardNo WHERE FMemNo IN(SELECT FMemNo FROM TMember) SELECT FMemNo FROM TImpMember GROUP BY FMemNo HAVING(SUM(1)) > 1 UPDATE TImpMember SET FMemNO = 'T' + FMemNO,FCardNo = 'T'+ FCardNo UPDATE A SET A.FMemNo = B.FCardNo FROM TImpMember AS A,( SELECT Id,MIN(CreateTime) AS CreateTime FROM TImpMember GROUP BY ID HAVING(SUM(1) > 1)) AS C,TImpMember AS B WHERE A.Id = B.ID AND A.ID = C.ID AND B.CreateTime = C.CreateTime UPDATE TImpMember SET FCompId = 1 UPDATE TImpMember SET FBirthdayType = 'G' 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, 0 AS FPoint, 1 AS FRecvConsSMS, 1 AS FRecvBulkSMS, '' AS FMemo, '从巧云导入' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5 from TImpMember 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, 1 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 WHERE FCardTypeId IS NOT NULL 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(),'从Excel中导入' FROM TImpMemberCard AS A INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo) SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,4787685675100222081,FBalance2,FBalance2,0,FCreateDate,null AS FExpiredDate,'' FROM TImpMemberCard AS A WHERE 1=1 AND 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,4787685675100222081,getdate(),A.FCardTypeId,A.FCompId,'DR','Import',0,'',A.FBalance2,0,A.FBalance2,0,getdate(),'从Excel中导入' FROM TImpMemberCard AS A WHERE 1=1 AND FBalance2 > 0 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,FCardTypeId,0,FItemId,FCompId,FPurTimes,FUsedPurTimes,FPurAmount,0,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,'巧云导入',1,FAdjustPrice FROM TImpMemberCourse AS A SELECT * FROM TImpMemberCourse WHERE FMemId IS NULL ALTER TABLE TImpMemberCourse ADD FId BIGINT UPDATE TImpMemberCourse SET FId = dbo.FNNewId() UPDATE TPAYAccount SET FId = 10 WHERE FNo = 'B' UPDATE TMemberCourseImportEx SET FId = dbo.FNNewId() SELECT * FROM TPayAccount SELECT * FROM TEmployee WHERE FId = 0 SELECT * FROM TIMpMember UPDATE A SET A.FMemo = b.REMARK FROM TIMpMember AS B,TMemberCard AS A WHERE A.FCardId = B.FCardId 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(FCardTypeId,0),getdate(),FPurTimes,0,FUsedPurTimes,0,FCompId,'DR','Import',0,'',0,getdate() FROM TImpMemberCourse AS A SELECT dbo.FNNewId(),FMemId,FCardId,0,FCardTypeId,FTime = getdate(),FPurTimes,0,0,0, 0,0,0,0,1, 'DR','Import',0,'',0 FROM TImpMemberCourse AS A SELECT * FROM TMember WHERE FMemId IN(SELECT FMemId FROM TMemberCOurse) SELECT FMemId,MIN(FId) FROM TMemberCourse GROUP BY FMemId DELETE TMemberCOurse WHERE FId NOT IN( SELECT MIN(FId) FROM TMemberCourse GROUP BY FMemId) UPDATE TImpMember SET FIsLOAD = 0 SELECT * FROM TImpMemberLog SELECT * FROM TImpMember WHERE FCardNO = '6011238' INSERT TMemberPointHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransId,FTransNo,FInAmount,FOutAmount,FBalance,FMemo,FRecordTime) SELECT dbo.FNNewId(),A.FMemId,getdate(),0,1,'DR','Import',0,'',FPoint,0,FPoint,'',getdate() FROM TImpMember AS A WHERE FPoint != 0 ALTER TABLE TImpMemberTransHistItem ADD FId BIGINT ALTER TABLE TImpMemberTransHist ADD FId BIGINT ALTER TABLE TImpMemberTransHist ADD FMemId BIGINT ALTER TABLE TImpMemberTransHist ADD FCompId BIGINT UPDATE TImpMemberTransHist SET FId = dbo.FNNewId() WHERE FId IS NULL UPDATE TImpMemberTransHistItem SET FId = dbo.FNNewId() WHERE FId IS NULL SELECT * FROM TImpMemberTransHistItem UPDATE A SET A.FMemId = B.FMemID, A.FCompId = B.FCompId FROM TImpMemberTransHist AS A,TImpMember AS B WHERE A.memberId = B.id INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo) SELECT B.FId,A.FMemId,A.createYmd,0,A.FCompId,'DR','Import',billTypeName,B.itemName,discountPrice,1,discountPrice,'',employees,'' FROM TImpMemberTransHist AS A ,TImpMemberTransHistItem AS B WHERE A.id = B.BillId AND B.FId NOT IN(SELECT FId FROM TMemberOldTransHist) SELECT * FROM TImpMember WHERE phone = '' AND FMobile = ''