SELECT * FROM TImpMember WHERE FMemNo iS NULL WHERE IsDel = 1 ORDER BY Id DESC alter table TImpMember drop column FBirthday ALTER TABLE TImpMember ADD FCompId AS 1 ALTER TABLE TImpMember ADD FMemId AS 100000 + ID ALTER TABLE TImpMember ADD FName AS Name ALTER TABLE TImpMember ADD FGender AS CASE Sex WHEN 0 THEN 1 ELSE 0 END ALTER TABLE TImpMember ADD FBriefCode AS HelpMemory ALTER TABLE TImpMember ADD FMobile AS PhoneNum ALTER TABLE TImpMember ADD FCreateDate AS AddDate ALTER TABLE TImpMember ADD FMemo AS Remark ALTER TABLE TImpMember ADD FBirthday AS CASE WHEN ISNULL(Birth,'') = '' THEN '' ELSE CASE WHEN LEN(Birth) < 12 THEN '9999-' ELSE '' END + REPLACE(REPLACE(Birth,'BTrue',''),'BFalse','') END ALTER TABLE TImpMember ADD FBirthdayType AS CASE WHEN Birth LIKE '%BFalse%' THEN 'L' ELSE 'G' END ALTER TABLE TImpMember ADD FMemNo VARCHAR(50) ALTER TABLE TImpCard ADD FCardNo VARCHAR(50) ALTER TABLE TImpCard ADD FMemId AS 100000 + GuestId ALTER TABLE TImpCard ADD FCardId AS 100000 + ID ALTER TABLE TImpCard ADD FCardTypeId AS CardTypeId ALTER TABLE TImpCard ADD FBalance AS MoneyAccountBalance ALTER TABLE TImpCard ADD FCreateDate AS AddDate ALTER TABLE TImpCard ADD FExpiredDate AS EndDate ALTER TABLE TImpCard ADD FValueType AS 1 ALTER TABLE TImpCard ADD FCompId AS 1 ALTER TABLE TImpCard ADD FCardState AS 1 ALTER TABLE TImpCard ADD FRemainTimes AS 0 ALTER TABLE TImpCard ADD FMemo AS '' ALTER TABLE TImpCard ADD FMemIndex INT ALTER TABLE TImpCard ADD FCardIndex INT UPDATE TImpCard SET FMemIndex = 0; UPDATE A SET A.FMemIndex = (SELECT COUNT(1) FROM TImpCard AS B WHERE B.GuestId = A.GuestId AND B.AddDate > A.AddDate) FROM TImpCard AS A UPDATE A SET A.FCardIndex = (SELECT COUNT(1) FROM TImpCard AS B WHERE B.CardNum = A.CardNum AND B.AddDate > A.AddDate) FROM TImpCard AS A UPDATE TImpCard SET FCardNo = CardNum UPDATE A SET A.FCardNo = A.CardNum + '_' + CAST(A.FCardIndex AS VARCHAR) FROM TImpCard AS A WHERE A.FCardIndex > 0 UPDATE A SET A.FMemNo = A.FMobile FROM TImpMember AS A UPDATE A SET A.FMemNo = A.FName FROM TImpMember AS A WHERE ISNULL(FMobile,'') = '' UPDATE A SET A.FMemNo = B.FCardNo FROM TImpMember AS A,TImpCard AS B WHERE A.Id = B.GuestId AND B.FIndex= 0 SELECT * FROM TImpMember WHERE FMemNo iS NULL SELECT FMemNo,SUM(1) FROM TImpMember WHERE Id IN(SELECT GuestId FROM TImpCard) GROUP BY FMemNo ORDER BY SUM(1) DESC SELECT * FROM TImpCard WHERE GuestId IN( SELECT * FROM TImpMember WHERE FMemNo = '13206333611' ) SELECT * FROM TImpCard GROUP BY CardTypeId,CardTypeName SELECT * FROM TImpCard WHERE GuestId = 1082 SELECT * FROM TImpMember WHERE Id = 9910 SELECT * FROM TMemberCardType ORDER BY LEN(FName) -- ALTER TABLE TMemberCardType ALTER COLUMN FName VARCHAR(100) NOT NULL DEFAULT '' 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 = CardTypeId,CardTypeId,REPLACE(dbo.FNToDBC(CardTypeName),' ',''),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 TImpCard GROUP BY CardTypeId,CardTypeName SELECT CardTypeName FROM TImpCard ORDER BY LEN(CardTypeName) DESC 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) UPDATE TImpCard SET FCardNo SELECT FCardNo FROM TImpCard GROUP BY FCardNo HAVING(SUM(1)) > 1 ORDER BY SUM(1) DESC SELECT * FROM TImpCARD WHERE FCardNO = '1300056' --²εΘλ»αΤ± 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 A.FMemId, A.FMemNo, A.FName, A.FBriefCode, 0 AS FTypeId, FCompId, A.FCreateDate, A.FGender, A.FBirthdayType AS FBirthdayType, A.FBirthday, '' AS FTelephone, A.FMobile, '' AS FQQ, '' AS FWeChat, '' AS FIdCard, '' AS FEmail, '' AS FAddress, 0 AS FProId, ISNULL('','') AS FCPW, ISNULL('','') AS FQPW, 0 AS FChargeEmpId, 0 AS FPoint, 1 AS FRecvConsSMS, 1 AS FRecvBulkSMS, A.FMemo AS FMemo, '' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5 from TImpMember AS A WHERE A.IsDel = 0 AND A.Id IN(SELECT GuestId FROM TImpCard) INSERT INTO dbo.TMemberCard( FCardId, FCardNo, FCardFaceNo, FTypeId, FValueType, FCompId, FMemId, FState, FCreateDate, FExpiredDate, FTotalTimes, FUsedTimes, FSaleCompId, FSaleBillId, FMemo) SELECT FCardId AS FId, FCardNo AS FNo, FCardNo AS FFaceNo, FCardTypeId, 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, FMemo AS FMemo FROM TImpCard WHERE IsDel = 0 UPDATE TMemberCard SET FExpiredDate = '9000-01-01' WHERE FExpiredDate = '1900-01-01' 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 TImpCard WHERE FCardId IS NOT NULL 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,TImpCard AS D where C.FCardId = A.FCardId AND C.FCardId = D.FCardId