SELECT 积分 FROM imp_member_list select 会员编号,姓名,性别,手机号码,生日,入会日期,ISNULL(积分,0) as 积分 INTO imp_member FROM imp_member_list group by 会员编号,姓名,性别,手机号码,生日,入会日期,ISNULL(积分,0) SELECT 会员编号 FROM imp_member GROUP BY 会员编号 HAVING SUM(1) > 1 select 会员编号,会员卡号,卡类别,开卡日期,有效日期,疗程销售金额,剩余次数,使用次数 into imp_member_card FROM imp_Member_list group by 会员编号,会员卡号,卡类别,开卡日期,有效日期,疗程销售金额,剩余次数,使用次数 select 会员卡号 from imp_Member_card where 会员卡号 Is not null group by 会员卡号 having sum(1) > 1 SELECT 会员卡号, 账户名称,[账户余额   #] as 账户余额 INTO imp_member_card_account FROM imp_Member_list where 会员卡号 Is not null GROUP BY 会员卡号,账户名称,[账户余额   #] ALTER TABLE imp_member ADD FMemId BIGINT ALTER TABLE imp_member ADD FCardNo VARCHAR(50) ALTER TABLE imp_member ADD FMemNo VARCHAR(50) ALTER TABLE imp_member ADD FName VARCHAR(50) ALTER TABLE imp_member ADD FGender INT ALTER TABLE imp_member ADD FMobile VARCHAR(50) ALTER TABLE imp_member ADD FCardTypeId BIGINT ALTER TABLE imp_member ADD FCourseId BIGINT ALTER TABLE imp_member ADD FBalance DECIMAL(18,6) ALTER TABLE imp_member ADD FBalance2 DECIMAL(18,6) ALTER TABLE imp_member ADD FRemainTimes INT ALTER TABLE imp_member ADD FPurTimes INT ALTER TABLE imp_member ADD FPurAmount DECIMAL(18,6) ALTER TABLE imp_member ADD FItemId BIGINT ALTER TABLE imp_member ADD FCreateDate DATETIME ALTER TABLE imp_member ADD FExpiredDate DATETIME ALTER TABLE imp_member ADD FCompId BIGINT ALTER TABLE imp_member ADD FCardId BIGINT ALTER TABLE imp_member ADD FMemo VARCHAR(1000) ALTER TABLE imp_member ADD FArrear DECIMAL(18,6) ALTER TABLE imp_member ADD FPoint DECIMAL(18,6) ALTER TABLE imp_member ADD FBirthday DATETIME ALTER TABLE imp_member ADD FBirthdayType CHAR ALTER TABLE imp_member ADD FCustom1 VARCHAR(100) ALTER TABLE imp_member_card ADD FMemId BIGINT ALTER TABLE imp_member_card ADD FCardNo VARCHAR(50) ALTER TABLE imp_member_card ADD FCardTypeId BIGINT ALTER TABLE imp_member_card ADD FCourseId BIGINT ALTER TABLE imp_member_card ADD FRemainTimes INT ALTER TABLE imp_member_card ADD FPurTimes INT ALTER TABLE imp_member_card ADD FPurAmount DECIMAL(18,6) ALTER TABLE imp_member_card ADD FItemId BIGINT ALTER TABLE imp_member_card ADD FCreateDate DATETIME ALTER TABLE imp_member_card ADD FExpiredDate DATETIME ALTER TABLE imp_member_card ADD FCompId BIGINT ALTER TABLE imp_member_card ADD FCardId BIGINT ALTER TABLE imp_member_card ADD FMemo VARCHAR(1000) ALTER TABLE imp_member_card ADD FArrear DECIMAL(18,6) ALTER TABLE imp_member_card ADD FPoint DECIMAL(18,6) ALTER TABLE imp_member_card ADD FBirthday DATETIME ALTER TABLE imp_member_card ADD FBirthdayType CHAR ALTER TABLE imp_member_card ADD FCustom1 VARCHAR(100) ALTER TABLE imp_member_card ADD FCardTYpeName VARCHAR(100) ALTER TABLE imp_member_card ADD FCardTypeNo VARCHAR(100) ALTER TABLE imp_member_card_account ADD FMemId BIGINT ALTER TABLE imp_member_card_account ADD FCardID BIGINT ALTER TABLE imp_member_card_account ADD FACCTId BIGINT ALTER TABLE imp_member_card_account ADD FCreateDate DATETIME ALTER TABLE imp_member_card_account ADD FBalance DECIMAL(18,6) --初始化卡类别 UPDATE imp_member_card SET FCardTYpeNo = left(卡类别,CHARINDEX('-',卡类别)-1) UPDATE imp_member_card SET FCardTYpeName = substring(卡类别,CHARINDEX('-',卡类别) + 1,len(卡类别)) DROP TABLE TImpCardType CREATE TABLE TImpCardType ( FId BIGINT, FNo VARCHAR(50), FName VARCHAR(50), FType VARCHAR(50), FValueType INT ) INSERT TImpCardType(FId,FNo,FName,FValueType) SELECT dbo.FNNewId(),'Y' + FCardTypeNo,FCardTypeName,1 FROM imp_member_card WHERE 会员卡号 IS NOT NULL GROUP BY FCardTYpeNo,FCardTYpeName 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,FNo,FName,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 imp_member UPDATE imp_Member SET FMemID = dbo.FNNewId() UPDATE imp_Member SET FCreateDate = 入会日期 UPDATE imp_Member SET FGender = case when 性别 = '男' then 1 else 0 end UPDATE imp_Member SET FBirthday = 生日 UPDATE imp_Member SET FPoint = 积分 UPDATE imp_member SET FMemNo= 会员编号 UPDATE imp_member SET FName = 姓名 UPDATE imp_member SET FMobile = 手机号码 UPDATE imp_member SET FBirthdayType = 'G' update imp_member_card SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL UPDATE A SET A.FMemId = B.FMemId FROM imp_member_card AS A,imp_member AS B WHERE A.会员编号= b.会员编号 --卡号 UPDATE imp_member_card SET FCardId = dbo.FNNewId() UPDATE imp_member_card SET FCardNo = 会员卡号 UPDATE imp_member_card SET FCreateDate = 开卡日期 UPDATE imp_member_card SET FExpiredDate = 有效日期 UPDATE A SET A.FCardTypeId = B.FId FROM imp_member_card AS A,TImpCardType AS B WHERE 'Y'+ A.FCardTypeNo = B.Fno SELECT * FROM imp_member_card --卡门店 UPDATE imp_member SET FCardId = dbo.FNCompId('001') UPDATE imp_member_card SET FCompId = dbo.FNCompId('001') --余额 UPDATE imp_member_card_account SET 账户余额 = REPLACE(账户余额,char(10),'') UPDATE imp_member_card_account SET 账户余额 = REPLACE(账户余额,char(13),'') UPDATE imp_member_card_account SET FBalance = cast(账户余额 as float) select * from imp_member_card_account UPDATE imp_member_card_account SET 账户名称 = REPLACE(账户名称,' ','') UPDATE imp_member_card_account SET 账户名称 = REPLACE(账户名称,' ','') UPDATE imp_member_card_account SET 账户名称 = REPLACE(账户名称,char(10),'') UPDATE imp_member_card_account SET 账户名称 = REPLACE(账户名称,char(13),'') UPDATE A SET A.FMemId = B.FMemId, A.FCardId = B.FCardID, A.FCreateDate = B.FCreateDate FROM imp_member_card_account AS A,imp_member_card AS B WHERE a.会员卡号= B.会员卡号 UPDATE A SET A.FAcctId = B.FId FROM imp_member_card_account AS A,TPayAccount AS B WHERE A.账户名称 = B.FName SELECT dbo.FNNewId() AS FId,账户名称 AS FName into imp_account FROM imp_member_card_account WHERE FAcctId IS NULL GROUP BY 账户名称 INSERT TPayAccount(FId,FNo,FName,FDescription,FIsAccount,FAllowEdit,FItemBizRate,FGoodsBizRate,FCardBizRate,FItemPerfRate,FGoodsPerfRate,FCardPerfRate,FItemPointRate,FGoodsPointRate,FCardPointRate,FIsCashIncome,FIsBizIncome,FIsCashPerf,FIsLabor,FCourseIsLabor,FEnabled,FOrder,FMemberDisplay) SELECT A.FId,A.FName,A.FName ,'导入账户',FIsAccount,FAllowEdit,FItemBizRate,FGoodsBizRate,FCardBizRate,FItemPerfRate,FGoodsPerfRate,FCardPerfRate,FItemPointRate,FGoodsPointRate,FCardPointRate,FIsCashIncome,FIsBizIncome,FIsCashPerf,FIsLabor,FCourseIsLabor,FEnabled,FOrder,FMemberDisplay FROM TPayAccount AS B,imp_account AS A WHERE b.fid = 3 UPDATE imp_member_card SET FCreateDate = DATEADD(second,cast(opendate as bigint) / 1000,'1970-01-01 00:00:00') UPDATE imp_member_card SET FExpiredDate = DATEADD(YEAR,100,FCreateDate) UPDATE A SET A.FExpiredDate = DATEADD(minute,s ,'1970-01-01 00:00:00') FROM imp_member_card AS A,( SELECT id,(cast(invaliddate as bigint) / cast(1000 as bigint)) / 60 as s FROM imp_member_card where invaliddate != '' ) AS B WHERE A.id = B.id SELECT * FROM imp_member_card WHERE cast(presentfee as float)> 0.0 --会员编号 UPDATE A SET A.FMemNo = B.FCardNo FROM imp_member AS A,imp_member_card AS B WHERE A.Id = b.memberid --shopId UPDATE A SET A.FCompId = B.FCompID FROM imp_member AS A,TImpCompany AS B WHERE A.shopId = B.shopId 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, ISNULL(FCreateDate ,'1900-01-01') 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, ISNULL( FPoint,0) AS FPoint, 1 AS FRecvConsSMS, 1 AS FRecvBulkSMS, ISNULL(FMemo,'') AS FMemo, '' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5 from imp_member INSERT INTO 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 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, ISNULL(FRemainTimes,0) AS FTotalTimes, 0 AS FUsedTimes, FCompId AS FSaleCompId, 0 AS FSaleBillId, ISNULL(FMemo,'' ) AS FMemo FROM imp_member_card WHERE 会员卡号 is not null INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo) SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,FAcctId,FBalance,FBalance,0,FCreateDate,NULL AS FExpiredDate,'' FROM imp_member_card_account 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,FAcctId,getdate(),B.FCardTypeId,B.FCompId,'DR','Import',0,'',A.FBalance,0,A.FBalance,0,getdate(),'导入' FROM imp_member_card_account AS A,imp_member_card as b where a.fcardid = b.fcardid --疗程 --储值卡里面的疗程卡 SELECT dbo.FNNewId() AS item_id,dbo.FNNewId() AS course_id,FCardTypeName AS name,FCardTypeNo AS no INTO imp_item FROM imp_member_card WHERE 会员卡号 is null GROUP BY FCardTypeNo,FCardTypeName ALTER TABLE imp_member_card ADD FUsedTimes INT ALTER TABLE imp_member_card ADD FAdjustPrice DECIMAL(18,6) UPDATE imp_member_card SET FPurTimes = CAST(使用次数 AS FLOAT)+CAST(剩余次数 AS FLOAT) UPDATE imp_member_card SET FUsedTimes = 使用次数 UPDATE imp_member_card SET FPurAmount = 疗程销售金额 UPDATE imp_member_card SET FAdjustPrice = FPurAmount / FPurTimes where FPurTimes > 0 UPDATE imp_member_card SET FMemo = '' UPDATE A SET A.FCourseId = B.course_id, A.FItemId = B.item_id FROM imp_member_card AS A,imp_item AS B WHERE A.FCardTypeName = b.name AND 会员卡号 is null --疗程 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,FCourseId,0,FItemId,FCompId,FPurTimes,FUsedTimes,FPurAmount,0,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,FMemo,1,FAdjustPrice FROM imp_member_card AS A where 会员卡号 is null 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(FCourseId,0),getdate(),FPurTimes,0,FUsedTimes,0,FCompId,'DR','Import',0,'',0,getdate() FROM imp_member_card AS A where 会员卡号 is null 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 item_id,''+no,name,name,name,0,dbo.FNGetFirstPinYin(name),'',1,1,1,'','','',1,0,0,0,0,0,0,0,1 FROM imp_item INSERT INTO TCourse(FId,FNo,FName,FBriefCode,FItemId,FPackId,FSequence,FTypeId,FTimes,FFreeTimes,FDurable,FValidityPeriodUnit,FValidityPeriod,FCreateDate,FExpiredDate,FDescription,FEnabled,FPrice,FAmount,FCalcMode) SELECT course_id AS FId, '' + A.no + '', A.name AS FName, '' AS FBriefCode, A.item_id AS FItemId, 0 AS FPackId, 1 AS FSequence, 0,--(SELECT TOP 1 FId FROM TBasicType WHERE FKey = 'CourseType') AS FTypeId, ISNULL(0,0) AS FTimes, 0 AS FFreeTimes, 0 AS FDurable, 1 AS FValidityPeriodUnit, 100 AS FValidityPeriod, getdate() AS FCreateDate, NULL AS FExpiredDate, '' AS FDescription, 1 AS FEnabled, 0 AS FPrice, 0 AS FAmount, 1 AS FCalcMode FROM imp_item AS A 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 != 0 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 item_id FROM imp_item) AND C.FNo in('001','000') INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo) SELECT DBO.FNNewId(),A.mem_id,dateadd(second,cast(createDate as bigint)/1000,'1970-01-01'),0,A.comp_id,'DR','Import',billno,comment,consumefee,1,consumefee,'',isnull('','') + ',' + isnull('','') + ',' + isnull('',''),'' FROM imp_member_trans_hist AS A order by createDate select * from imp_member_trans_hist