use chongqing_kadiya1 ALTER TABLE TImpMember ADD FCourseId BIGINT ALTER TABLE TImpMember ADD FItemId BIGINT ALTER TABLE TImpMember ADD FMemId BIGINT ALTER TABLE TImpMember ADD FMemNo VARCHAR(50) ALTER TABLE TImpMember ADD FCardnO VARCHAR(50) ALTER TABLE TImpMember ADD FCardTypeId BIGINT ALTER TABLE TImpMember ADD FName VARCHAR(50) ALTER TABLE TImpMember ADD FMobile VARCHAR(50) ALTER TABLE TImpMember ADD FMemo VARCHAR(1000) ALTER TABLE TImpMember ALTER COLUMN FMemo VARCHAR(8000) ALTER TABLE TImpMember ADD FBirthday DATETIME ALTER TABLE TImpMember ADD FCreateDate DATETIME ALTER TABLE TImpMember ADD FIsCourse BIT ALTER TABLE TImpMember ADD FCompId BIGINT ALTER TABLE TImpMember ADD FBirhtday DATETIME ALTER TABLE TImpMember ADD FPW VARCHAR(50) ALTER TABLE TImpMember ADD FGender INT ALTER TABLE TImpMember ADD FBriefCode VARCHAR(50) ALTER TABLE TImpMember ADD FExpiredDate VARCHAR(100) ALTER TABLE TImpMember ADD FBalance DECIMAL(18,6) ALTER TABLE TImpMember ADD FRemainTimes DECIMAL(18,6) ALTER TABLE TImpMember ADD FCardId BIGINT ALTER TABLE TImpMember ADD FCardState INT ALTER TABLE TImpMember ADD FCalcMode INT ALTER TABLE TImpMember ADD FValueType INT 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 = dbo.FNNewId(),卡名称 AS FNo,卡名称,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 TImpMember GROUP BY 卡名称 ORDER BY 卡名称 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 = dbo.FNCompId('001') AND NOT EXISTS(SELECT TOP 1 1 FROM TMemberCardTypeSub AS B WHERE B.FCompId = C.FId AND B.FCardTypeId = I.FId) SELECT * FROM TImpMember UPDATE TImpMember SET FMemId = dbo.FNNewId() WHERE FMemId IS NULL UPDATE TImpMember SET FName = 会员姓名 UPDATE TImpMember SET FMobile = 会员手机 UPDATE TImpMember SET FMemNo = 卡号 UPDATE TImpMember SET FCardNO = 卡号 UPDATE TImpMember SET FBalance = [卡余额(元)] UPDATE TImpMember SET FCompId = dbo.FNCompId('001') UPDATE TImpMember SET FCreateDate = GETDATE() UPDATE TImpMember SET FExpiredDate = '9000-01-01' UPDATE TImpMember SET FBirthday = NULL UPDATE TImpMember SET FGender = 0 UPDATE TImpMember SET FCardState = 1 UPDATE TImpMember SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL UPDATE A SET A.FCardTypeId = B.FId FROM TImpMember AS A,TMemberCardType AS B WHERE A.卡名称 = B.FName SELECT * FROM TImpMember2 UPDATE TImpMember2 SET 会员卡号 = replace(会员卡号,' ','') UPDATE TImpMember2 SET 会员卡号 = replace(会员卡号,' ','') UPDATE TImpMember2 SET 会员卡号 = replace(会员卡号,' ','') UPDATE TImpMember2 SET 开卡时间 = replace(开卡时间,' ','') UPDATE TImpMember2 SET 开卡时间 = replace(开卡时间,' ','') UPDATE TImpMember2 SET 开卡时间 = replace(开卡时间,'"','') UPDATE TImpMember2 SET 开卡时间 = LEFT(开卡时间,10 ) + ' ' + RIGHT(开卡时间,8) SELECT * FROM TIMpMember2 UPDATE TIMpMember SET FGender = 0 UPDATE A SET A.FGender =1 FROM TIMpMember AS A,TIMpMember2 AS B WHERE A.卡号 = B.会员卡号 AND ISNULL(B.会员性别,'') = '男' UPDATE A SET A.FMemo = ISNULL(会员备注,''), A.FCreateDate = ISNULL(开卡时间,getdate()) FROM TIMpMember AS A,TIMpMember2 AS B WHERE A.卡号 = B.会员卡号 UPDATE A SET A.FCreateDate = B.FCreateDate, A.FGender = B.FGender FROM TMember AS A,TImpMember AS B WHERE A.FMemId = B.FMemId UPDATE A SET A.FCreateDate = B.FCreateDate, A.FMemo = B.FMemo FROM TMemberCard AS A,TImpMember AS B WHERE A.FMemId = B.FMemId --插入会员 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, FMemNo, FName, dbo.FNGetFirstPinYin(FName), 0 AS FTypeId, FCompId, FCreateDate, FGender, 'G' AS FBirthdayType, FBirthday, '' AS FTelephone, FMobile , '' AS FQQ, '' AS FWeChat, '' AS FIdCard, '' AS FEmail, '' AS FAddress, 0 AS FProId, ISNULL(FPW,'') AS FCPW, ISNULL(FPW,'') AS FQPW, 0 AS FChargeEmpId, 0 AS FPoint, 1 AS FRecvConsSMS, 1 AS FRecvBulkSMS, '', '' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5 from TImpMember -- INSERT INTO dbo.TMemberCard( FCardId, FCardNo, FCardFaceNo, FTypeId, FValueType, FCompId, FMemId, FState, FCreateDate, FExpiredDate, FTotalTimes, FUsedTimes, FSaleCompId, FSaleBillId, FMemo) SELECT FCardId AS FId, FMemNo AS FNo, FMemNo AS FFaceNo, FCardTypeId, 1 AS FValueType, FCompId AS FCompId, FMemId AS FMemId, FCardState AS FState, FCreateDate AS FCreateDate, FExpiredDate AS FExpiredDate, ISNULL(FRemainTimes,0) AS FTotalTimes, 0 AS FUsedTimes, 0 AS FSaleCompId, 0 AS FSaleBillId, ISNULL(FMemo,'') AS FMemo FROM TImpMember INSERT TMemberCardAccount(FId,FMemId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo) SELECT dbo.FNNewId(),FMemId,FCardId AS FCardId,3,ISNULL(FBalance,0),ISNULL(FBalance,0),0,FCreateDate,NULL,'' FROM TImpMember WHERE FCalcMode != 1 INSERT dbo.TMemberCardAcctHist(FId,FMemId,FCardId,FAcctId,FTime,FCardTypeId,FCompId,FBillType,FBizType,FTransId,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo) select dbo.FNNewId(),C.FMemId,A.FCardId,A.FAcctId,getdate(),C.FTypeId,C.FCompId,'DR','Import',0,'',ISNULL(A.FBalance,0),0,ISNULL(A.FBalance,0),0,getdate(),'' from dbo.TMemberCardAccount AS A,dbo.TMemberCard AS C,TImpMember AS D where C.FCardId = A.FCardId AND C.FCardId = D.FCardId SELECT * FROM TImpMemberTransHist DELETE TImpMemberTransHist WHERE 卡号 = '' AND 交易流水号 IS NULL DELETE TMemberOldTransHist ALTER TABLE TImpMemberTransHist ADD FMemId BIGINT ALTER TABLE TImpMemberTransHist ADD FCardId BIGINT ALTER TABLE TImpMemberTransHist ADD FCompId BIGINT UPDATE TImpMemberTransHist SET FCompId = dbo.FNCompId('001') UPDATE A SET A.FMemId = B.FMemId, A.FCardId = B.FCardId FROM TImpMemberTransHist AS A,TImpMember AS B WHERE A.卡号 = B.卡号 INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo) SELECT DBO.FNNewId(),A.FMemId,A.交易时间,0,A.FCompId,'DR','Import',交易流水号,交易类型,CAST([收入(实际收入)] AS FLOAT) + CAST([支出(实际支出)] AS FLOAT), 1,CAST([收入(实际收入)] AS FLOAT) + CAST([支出(实际支出)] AS FLOAT),'','','' FROM TImpMemberTransHist AS A WHERE ISNULL(FMemId,0) != 0