use jiaonan_xinjixing DROP TABLE TImpCardType CREATE TABLE TImpCardType ( FCardTypeId BIGINT, FCardTypeNo VARCHAR(20), FCardTypeName VARCHAR(30), FValueType INT ) SELECT * FROM TImpMemberCard SELECT * FROM TImpCardType INSERT TImpCardType(FCardTypeId,FCardTypeNo,FCardTypeName,FValueType) SELECT dbo.FNNewId(),klx,klx,1 FROM TImpMember GROUP BY klx ALTER TABLE TImpCardType ADD FId BIGINT UPDATE TImpCardType SET FId = dbo.FNNewId() 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,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 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 WHERE FClientNO = '0003' ALTER TABLE TImpMember ADD FIsLoad BIT NOT NULL DEFAULT 0 ALTER TABLE TImpMember ADD FCardTypeName VARCHAR(100) ALTER TABLE TImpMember ADD FMemId BIGINT ALTER TABLE TImpMember ADD FMemNo VARCHAR(50) ALTER TABLE TImpMember ADD FCardNo VARCHAR(50) ALTER TABLE TImpMember ADD FName VARCHAR(50) ALTER TABLE TImpMember ADD FGender INT ALTER TABLE TImpMember ADD FCardState INT ALTER TABLE TImpMember ADD FMobile VARCHAR(50) ALTER TABLE TImpMember ADD FCardTypeId BIGINT ALTER TABLE TImpMember ADD FCourseId BIGINT ALTER TABLE TImpMember ADD FBalance DECIMAL(18,6) ALTER TABLE TImpMember ADD FBalance2 DECIMAL(18,6) ALTER TABLE TImpMember ADD FRemainTimes INT ALTER TABLE TImpMember ADD FPurTimes INT ALTER TABLE TImpMember ADD FPurAmount DECIMAL(18,6) ALTER TABLE TImpMember ADD FItemId BIGINT ALTER TABLE TImpMember ADD FCreateDate DATETIME ALTER TABLE TImpMember ADD FExpiredDate DATETIME ALTER TABLE TImpMember ADD FCompId BIGINT ALTER TABLE TImpMember ADD FCardId 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 FState INT ALTER TABLE TImpMember ADD FBirthday DATETIME ALTER TABLE TImpMember ADD FBirthdayType CHAR SELECT * FROM TImpMember UPDATE A SET A.FMobile = ISNULL(A.dh,''), A.FName = ISNULL(a.xm,''), A.FGender = CASE WHEN ISNULL(A.xb,'') = '男' THEN 1 ELSE 0 END FROM TImpMember AS A SELECT FMemId ,FCardNO,FMemNO,FCardId FROM TImpMember UPDATE TImpMember SET FMemId = id UPDATE TImpMember SET FCardid = dbo.FNNewId() WHERE FCardid IS NULL UPDATE TImpMember SET FMemNo = kh UPDATE TImpMember SET FCardNO = FMemNo UPDATE A SET A.FCardTypeID = B.FCarDtYPEiD FROM TImpMember AS A,TImpCardType AS B WHERE A.klx = B.FCardTypeNo UPDATE TImpMember SET FBalance = CAST(ye AS FLOAT) SELECT * FROM TImpMember DELETE TImpMember WHERE FCardState = '待售' UPDATE TImpMember SET FCardState = 1 WHERE zt = '正常' UPDATE TImpMember SET FState = 4 WHERE zt != '正常' UPDATE TImpMember SET FMemo = bz UPDATE TImpMember SET FPoint = jf UPDATE TImpMember SET FBirthday = LEFT(sr,4) + '-' + SUBSTRING(sr,5,2) + '-' + RIGHT(sr,2) WHERE sr != '' AND len(sr )= 8 AND sr > '1' SELECT sr , CAST(LEFT(sr,4) + '-' + SUBSTRING(sr,5,2) + '-' + RIGHT(sr,2) AS DATETIME) FROM TImpMember WHERE sr != '' AND len(sr )= 8 AND sr > '1' ORDER BY sr UPDATE TImpMember SET FBirthdayType = 'G' UPDATE TImpMember SET FBirthdayType = 'L' UPDATE TImpMember SET FName = FMemNo WHERE ISNULL( FName,'') = '' UPDATE TImpMember SET FCompID = 1 UPDATE TImpMember SET FCreateDate = kksj UPDATE TImpMember SET FCreateDate = kksj UPDATE TImpMember SET FExpiredDate = DATEADD(YEAR,100,FCreateDate ) WHERE FExpiredDate = '1900-01-01 00:00:00.000' UPDATE A SET A.FExpiredDate = B.FExpiredDate FROM TMemberCard AS A,TImpmember AS B WHERE A.FCardID = B.FCardid SELECT * FROM TImpMember ORDER BY FExpiredDate 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, FCardState AS FState, FCreateDate AS FCreateDate, FExpiredDate, 0 AS FTotalTimes, 0 AS FUsedTimes, FCompId AS FSaleCompId, 0 AS FSaleBillId, ISNULL(FMemo,'') AS FMemo FROM TImpMember INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo) SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,3,FBalance,FBalance,0,FCreateDate, FExpiredDate,'' FROM TImpMember 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 TImpMember AS A WHERE FCardTypeId IS NOT NULL SELECT * FROM TMemberCardType WHERE FNo = '08' SELECT * FROM TMemberCard WHERE FTypeId = 7454692549301509161 UPDATE A SET A.FTypeId = B.FId FROM TMemberCard AS A,TMemberCardType AS B WHERE A.FCardNo BETWEEN '3305' AND '3339' AND A.FTypeId = 7454692549301509161 AND B.FNo = '10' UPDATE A SET A.FTypeId = B.FId FROM TMemberCard AS A,TMemberCardType AS B WHERE A.FCardNo LIKE '3%' AND A.FTypeId = 7454692549301509161 AND B.FNo = '09' UPDATE A SET A.FTypeId = B.FId FROM TMemberCard AS A,TMemberCardType AS B WHERE A.FCardNo LIKE '5%' AND A.FTypeId = 7454692549301509161 AND B.FNo = '09' UPDATE A SET A.FTypeId = B.FId FROM TMemberCard AS A,TMemberCardType AS B WHERE (A.FCardNo LIKE '6%' OR A.FCardNo LIKE '9%') AND A.FTypeId = 7454692549301509161 AND B.FNo = '11' UPDATE A SET A.FTypeId = B.FId FROM TMemberCard AS A,TMemberCardType AS B WHERE (A.FCardNo LIKE '8%' OR A.FCardNo LIKE '8%') AND A.FTypeId = 7454692549301509161 AND B.FNo = '12' UPDATE A SET A.FTypeId = B.FId FROM TMemberCard AS A,TMemberCardType AS B WHERE (A.FCardNo LIKE '1%' OR A.FCardNo LIKE '2%') AND A.FTypeId = 7454692549301509161 AND B.FNo = '10' UPDATE A SET A.FCardTypeId = B.FTypeId FROM TMemberCard AS B,TMemberCardAcctHist AS A WHERE A.FCardId = B.FCardId 卡号3305-3339开头的卡都转入这个卡类别编号:10 剩余3开头的卡都转入这个卡类别编号:09 卡号5开头的卡都转入这个卡类别编号:09 卡号6或者9开头的卡都转入这个卡类别编号:11 卡号8开头的卡都转入这个卡类别编号:12 卡号1或者2的卡都转入这个卡类别的编号:10 只是处理原来卡类别08-新卡内的卡号 UPDATE A SET A.FAcctId = (SELECT FId FROM TPayAccount WHERE FNo = '31') FROM TMemberCardAcctHist AS A,TMemberCard AS B WHERE B.FCardId = A.FCardId AND B.FTypeId IN( SELECT FId FROM TMemberCardType WHERE FNo BETWEEN '01' AND '07' ) UPDATE TMemberCard SET FEXPIREDDate = '' SELECT *INTO TImpMemberTransHist FROM QingDao_WuHao_Old. dbo.a1mxf SELECT * FROM #Hist ALTER TABLE TImpMemberTransHist ADD FMemId BIGINT ALTER TABLE TImpMemberTransHist ADD FCardId BIGINT UPDATE A SET A.FMemId = B.FMemId, A.FCardId = B.FCardId FROM TImpMemberTransHist AS A,TImpMember AS B WHERE A.kh = B.kh sp_rename '#H' INSERT TMemberOldTransHist(FId,FCompId,FMemId,FTime,FCardId,FBIllType,FBizType,FTransNo,FCOntent,FPrice,FQuantity,FAmount,FPayment,Femployee,FMemo) SELECT id,1,FMemId,FTimeStr ,FCardId,'',fl,''AS FTransNo, ISNULL(xmmc,''),je,ISNULL(sl,1),je,ISNULL('',''),ISNULL(mfs ,'') + ',' + isnull(zl,'') , '' AS FMemo FROM TImpMemberTransHist WHERE FMemId IS NOT NULL AND FMemId IN(SELECT FMemId FROM TImpMember3) ALTER TABLE TImpMemberTransHist ADD FTimeStr VARCHAR(19) UPDATE TImpMemberTransHist SET FTimeStr = replace(replace(replace(replace(replace(replace(rq,'年','-'),'月','-'),'日',' '),'时',':'),'分',':'),'秒','') UPDATE TImpMemberTransHist SET FTimeStr = FTimeStr + '00' WHERE FTimeStr LIKE '%:' UPDATE TImpMemberTransHist SET REPLQ SELECT FTimeStr ,CAST(FTimeStr AS DATETIME) FROM TImpMemberTransHist ORDER BY FTimeStr