SELECT * FROM TImpMember sp_rename 'TImpMemberCard','TImpMember' SELECT * INTO TImpMemberCard FROM qd77._miaowei1.dbo.TImpMemberCard SELECT * INTO TImpMember FROM qd77._miaowei1.dbo.TImpMember SELECT * INTO TImpCardType FROM qd77._miaowei1.dbo.TImpCardType --卡类别 SELECT * FROM TImpCardType ALTER TABLE TImpCardType ADD FId BIGINT UPDATE TImpCardType SET FId = dbo.FNNewId() WHERE FId IS NULL 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 =FId, ''+ShowNo,Name,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 SELECT * FROM TImpCardType 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 NOT EXISTS(SELECT TOP 1 1 FROM TMemberCardTypeSub AS B WHERE B.FCompId = C.FId AND B.FCardTypeId = I.FId) AND I.FId IN(SELECT FId FROM TImpCardType) ALTER TABLE TImpMember ADD FIsLoad BIT NOT NULL DEFAULT 0 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 FRemainTimes DECIMAL(18,6) ALTER TABLE TImpMemberCard ADD FPurTimes INT ALTER TABLE TImpMemberCard ADD FPurAmount DECIMAL(18,6) ALTER TABLE TImpMemberCard ADD FItemId BIGINT ALTER TABLE TImpMemberCard ADD FCreateDate DATETIME ALTER TABLE TImpMemberCard ADD FExpiredDate DATETIME ALTER TABLE TImpMemberCard ADD FCourseId BIGINT ALTER TABLE TImpMemberCard ADD FMemo VARCHAR(1000) ALTER TABLE TImpMemberCard ADD FCardId BIGINT ALTER TABLE TImpMemberCard ADD FPoint DECIMAL(18,6) ALTER TABLE TImpMemberCard 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 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 SELECT * FROM TImpMember SELECT * FROM TMember WHERE FMemId IN(SELECT FMemId FROM TImpMember) UPDATE TImpMember SET FMemId = dbo.FNNewId() WHERE FMemId IS NULL UPDATE TImpMember SET FName = Name UPDATE TImpMember SET FMobile = MobilePhone UPDATE TImpMember SET FGender = CASE WHEN Sex = '男' THEN 1 ELSE '0' END UPDATE TImpMember SET FCreateDate = CreateTime UPDATE TImpMember SET FCompId = (SELECT FId FROM TCompany WHERE FNo = '001') UPDATE TImpMember SET FArrear = 欠款 UPDATE TImpMember SET FMemo = remark UPDATE TImpMember SET FPoint = 0 UPDATE TImpMember SET FCardState = 0 UPDATE TImpMemberCard SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL UPDATE TImpMemberCard SET FMemId = abs( CAST( CAST(MemberId AS BINARY(16)) AS BIGINT)) UPDATE TImpMemberCard SET FCardNo = CardCode UPDATE TImpMemberCard SET FBalance = CAST(Account_Balance AS FLOAT) UPDATE TImpMemberCard SET FCreateDate = CreateTime UPDATE TImpMemberCard SET FExpiredDate = dateadd(YEAR,100,FCreateDate); UPDATE TImpMemberCard SET FPoint = cast(JF as float) UPDATE TImpMemberCard SET FMemo = '' UPDATE TImpMemberCard SET FCompId = dbo.FNCompId('001') SELECT SELECT * FROM TImpMemberCard WHERE status != 1 UPDATE A SET A.FMemNO = B.FCardno FROM TImpMember AS A,TImpMemberCard AS B WHERE A.ID = B.MemberId UPDATE A SET A.FCardTypeId = B.FId FROM TImpMemberCard AS A,TImpCardType AS B WHERE A.CatetoryId = B.Id UPDATE A SET A.FMemId = B.FMemId FROM TImpMemberCard AS A,TImpMember AS B WHERE A.MemberId = B.Id --生日 UPDATE TImpMember SET FBirthday = NULL UPDATE TImpMember SET FBirthdayType = 'G' WHERE BirthType = 0 UPDATE TImpMember SET FBirthdayType = 'L' WHERE BirthType >= 1 SELECT * FROM TImpMember WHERE StatusReason NOT IN('正常','激活','挂失','换卡') UPDATE TImpMemberCard SET FCardState = 1 --重复编号 UPDATE A SELECT FMemNo,SUM(1) FROM TIMpMEMBER GROUP BY FMemNo ORDER BY SUM(1) DESC SELECT FCardnO,SUM(1) FROM TIMpMEMBER GROUP BY FCardnO ORDER BY SUM(1) DESC ALTER TABLE TImpMember ADD FSeq INT IDENTITY(1,1) ALTER TABLE TImpMember ADD FIndex INT NOT NULL DEFAULT 0 UPDATE A SET A.FIndex = 1+(SELECT COUNT(1) FROM TImpMember AS B WHERE A.FCardNo = B.FCardNo AND (A.FCreateDate > B.FCreateDate OR (A.FCreateDate = B.FCreateDate AND (A.FSeq > B.FSeq) ))) FROM TImpMember AS A SELECT * FROM TImpMember WHERE FIndex > 1 SELECT * FROM TImpShopInfo --交易历史 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 = 'BQ' + FMemNO where FMemNO IN(SELECT FMemNO FROM TMember UNION ALL SELECT FCardNo FROM TMemberCard) UPDATE TImpMemberCard SET FCardNo = 'BQ' + FCardNo where FCardNo IN(SELECT FMemNO FROM TMember UNION ALL SELECT FCardNo FROM TMemberCard) 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, 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, FCardState AS FState, FCreateDate AS FCreateDate, DATEADD(year,1, FCreateDate) AS FExpiredDate, 0 AS FTotalTimes, 0 AS FUsedTimes, FCompId AS FSaleCompId, 0 AS FSaleBillId, FMemo AS FMemo FROM TImpMemberCard SELECT FCardId FROM TImpMemberCard GROUP BY FCardId HAVING SUM(1) > 1 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 TImpMember AS A WHERE ISNULL(A.FBalance2 ,0)!= 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 TImpMember AS A WHERE ISNULL(A.FBalance2 ,0)!= 0 ALTER TABLE TImpMemberCardAcctHist ADD FCompId BIGINT ALTER TABLE TImpMemberCardAcctHist ADD FCardId BIGINT ALTER TABLE TImpMemberCardAcctHist ADD FMemId BIGINT UPDATE A SET A.FMemId = B.FMemId, A.FCardId = B.FCardId, A.FCompId = B.FCompId FROM TImpMemberCardAcctHist AS A,TImpMemberCard AS B WHERE A.AccountId = B.Account_Id SELECT * FROM TImpMemberCardAcctHist INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo) SELECT dbo.FNNewId(),A.FMemId,A.CreateTime,0,A.FCompId,'DR','Import',BillCode,CASE WHEN InOrOut = 'Input' THEN '消费' ELSE '充值' END,Money,1,Money,'','','' FROM TImpMemberCardAcctHist AS A delete TImpError ALTER TABLE TImpMemberAcctHist ADD FCompId BIGINT ALTER TABLE TImpMemberAcctHist ADD FShopId BIGINT ALTER TABLE TImpMemberAcctHist ADD FMemId BIGINT UPDATE A SET A.FMemId = B.FMemId FROM TImpMemberAcctHist AS A,TImpMEMBER AS B WHERE A.FCardId = B.FCardId UPDATE A SET A.FShopId = B.ShopId FROM TImpMember AS B,TImpMemberAcctHist AS A WHERE A.vhrShopName = B.ShopName UPDATE TImpMemberAcctHist SET FCompId = dbo.FNCompId('001') WHERE fShopId = 697 UPDATE TImpMemberAcctHist SET FCompId = dbo.FNCompId('002') WHERE fShopId = 784 UPDATE TImpMemberAcctHist SET FCompId = dbo.FNCompId('003') WHERE fShopId = 805 UPDATE TImpMemberAcctHist SET FCompId = dbo.FNCompId('004') WHERE fShopId = 3330 INSERT INTO TMemberCardOldAcctHist(FId,FMemId,FCardId,FAcctId,FTime,FCardTypeId,FCompId,FBizType,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo) SELECT intId,FMemId,FCardId,3,ISNULL(dtmOPDateTime,'1753-01-01'),0,ISNULL(FCompId,0),vhrdatatype,vhrBillCode,cast(decinmoney as float),cast(decoutmoney as float),0,0,dtmOPDateTime,vhrdatatype FROM TImpMemberAcctHist SELECT * FROM TImpMemberAcctHist WHERE FCompiD IS NULL SELECT * FROM TMemberCard WHERE FCardId = 38677 SELECT * FROM TImpMember WHERE CardNo = '8010735' SELECT * FROM TImpError WHERE CardId = 38677 SELECT INSERT TMemberPhoto(FMemId,FType,FImagePath) SELECT FMemId,1,vhrMainImage + '.jpg',FMemNo FROM TImpMember WHERE vhrMainImage != '' UPDATE TMemberPhoto SET FImagePath = REPLACE(FImagePath,'.jpg.jpg','.jpg') SELECT * FROM TMemberPhoto SELECT * FROM TImpMemberCard