use taiyuan_yihao drop table imp_member drop table imp_member_card SELECT COUNT(1) FROM imp_member_card SELECT COUNT(1) FROM imp_member SELECT * FROM imp_member SELECT * FROM imp_member_card --门店 SELECT * FROM imp_company ALTER TABLE imp_company ADD comp_id BIGINT ALTER TABLE imp_company ADD comp_no VARCHAR(20) UPDATE A SET A.comp_id = B.FId, A.comp_no = B.FNo FROM TIMpCompany AS A,TCompany AS B WHERE ShopId = '74803' AND B.FNo = '001' DROP TABLE imp_card_type CREATE TABLE imp_card_type ( id BIGINT, no VARCHAR(50), name VARCHAR(50), type VARCHAR(50), value_type INT ) ALTER TABLE imp_member ADD mem_id BIGINT ALTER TABLE imp_member_card ADD mem_id BIGINT ALTER TABLE imp_member_card ADD card_no VARCHAR(50) ALTER TABLE imp_member_card ADD card_id BIGINT ALTER TABLE imp_member_card ADD card_type_name VARCHAR(100) ALTER TABLE imp_member ADD mem_no VARCHAR(50) ALTER TABLE imp_member ADD name VARCHAR(50) ALTER TABLE imp_member ADD gender INT ALTER TABLE imp_member ADD mobile VARCHAR(50) ALTER TABLE imp_member ADD create_date DATETIME ALTER TABLE imp_member_card ADD card_type_id BIGINT ALTER TABLE imp_member_card ADD course_id BIGINT ALTER TABLE imp_member_card ADD balance DECIMAL(18,6) ALTER TABLE imp_member_card ADD balance2 DECIMAL(18,6) ALTER TABLE imp_member_card ADD remain_times INT ALTER TABLE imp_member_card ADD pur_times INT ALTER TABLE imp_member_card ADD free_times INT ALTER TABLE imp_member_card ADD used_pur_times INT ALTER TABLE imp_member_card ADD used_free_times INT ALTER TABLE imp_member_card ADD pur_amount DECIMAL(18,6) ALTER TABLE imp_member_card ADD item_id BIGINT ALTER TABLE imp_member_card ADD create_date DATETIME ALTER TABLE imp_member_card ADD expired_date DATETIME ALTER TABLE imp_member ADD comp_id BIGINT ALTER TABLE imp_member_card ADD comp_id BIGINT ALTER TABLE imp_member_card ADD card_id BIGINT ALTER TABLE imp_member ADD arrear DECIMAL(18,6) ALTER TABLE imp_member ADD point DECIMAL(18,6) ALTER TABLE imp_member ADD birthday DATETIME ALTER TABLE imp_member ADD birthday_type CHAR ALTER TABLE imp_member ADD custom1 VARCHAR(100) ALTER TABLE imp_member ADD point_text VARCHAR(100) ALTER TABLE imp_member_card ADD memo VARCHAR(1000) ALTER TABLE imp_member_card ADD card_kind VARCHAR(20) ALTER TABLE imp_member_card ADD calc_mode INT ALTER TABLE imp_member_card ADD adjust_price DECIMAL(18,6) --添加索引 alter table imp_member_card alter column id VARCHAR(50) alter table imp_member alter column id VARCHAR(50) CREATE unique CLUSTERED INDEX IX_TImpMemberCard ON imp_member_card (id) CREATE unique CLUSTERED INDEX IX_TImpMember ON imp_member (id) UPDATE Imp_member_card SET card_kind = 'Money' update imp_member_card set card_kind = 'Course' WHERE types in('["8"]','[]') UPDATE imp_member_card SET memo = '' WHERE memo IS NULL UPDATE imp_member SET memo = '' WHERE memo IS NULL --初始化卡类别 SELECT * FROM imp_member_card DELETE imp_card_type INSERT imp_card_type(id,no,name,value_type) SELECT dbo.FNNewId() AS FId,FNo,FName,FValueType FROM ( SELECT cardName AS FNo, cardName + '['+discount+']' AS FName ,1 AS FValueType FROM imp_member_card WHERE card_kind = 'Money' GROUP BY cardName,discount) AS A GROUP BY FNo,FName,FValueType UPDATE TMemberCard SET FTypeId = 0 WHERE FCardId IN(SELECT card_id FROM imp_member_card) --会员ID UPDATE imp_member SET MEM_ID = id UPDATE imp_member_card SET mem_id = clientId UPDATE imp_member_card SET card_id = id SELECT * FROM imp_member_card --开卡日期 UPDATE imp_member_card SET Expired_Date = dateadd(year,100,create_Date) WHERE expired_date IS NULL effectiveEndDate UPDATE A SET A.Create_Date = B.create_Date FROM imp_member_card AS A,imp_member AS B WHERE A.clientId = B.id --处理卡号 UPDATE imp_member_card SET card_no = cardCode --处理重复卡号 DROP TABLE #Card SELECT card_no into #Card FROM imp_member_card GROUP BY card_no HAVING(SUM(1)) > 1 ALTER TABLE imp_member_card ADD FSeq INT IDENTITY ALTER TABLE imp_member_card ADD FIndex INT UPDATE A SET A.FIndex = 1+(SELECT COUNT(1) FROM imp_member_card AS B WHERE A.FCardNo = B.FCardNo AND (A.FCreateDate > B.FCreateDate OR (A.FCreateDate = B.FCreateDate AND (A.FSeq > B.FSeq) ))) FROM imp_member_card AS A SELECT * FROM imp_member_card WHERE FCardNo IN(SELECT FCardNO FROM #Card) AND FIndex > 0 order by FCardNo --删除完全一样的 DELETE A FROM imp_member_card AS A, ( SELECT MemId,CardId,MIN(FSeq) AS FSeq FROM imp_member_card WHERE FCardNO iN(SELECT FCardNo FROM #Card) GROUP BY MemId,CardId HAVING(SUM(1)>1) ) AS B WHERE A.MemId = B.MemId AND A.CardId = B.CardId AND A.FSeq = B.FSeq UPDATE imp_member_card SET FCardNo = FCardNo + '.' + CAST(FIndex AS VARCHAR) WHERE FCardNo IN( SELECT FCardNo FROM #Card) /* UPDATE A SET A.FCardNo = B.FCardNo FROM imp_member_card AS A,imp_member_card AS B WHERE A.FMemId = B.FMemId AND A.FIndex > 1 AND B.FIndex = 1 */ SELECT FCardNo,SUM(1) AS Cnt FROM imp_member_card GROUP BY FCardNo ORDER BY SUM(1) DESC SELECT FMemNo,FMobile,SUM(1) AS Cnt FROM imp_member GROUP BY FMemNo ,FMobile ORDER BY SUM(1) DESC SELECT FMemNo,SUM(1) AS Cnt FROM imp_member WHERE FMemId IN(SELECT FMemId FROM imp_member_card) GROUP BY FMemNo ORDER BY SUM(1) DESC UPDATE imp_member_card SET card_id = id UPDATE imp_member_card SET card_id = dbo.FNNewId() WHERE card_id IS NULL --会员编号 UPDATE A SET A.mem_no = B.card_no FROM imp_member AS A,imp_member_card AS B WHERE A.id = B.clientId SELECT * FROM imp_member UPDATE imp_member SET name = clientName UPDATE imp_member SET mobile = mobilephone UPDATE imp_member SET gender = CASE WHEN sex = '1' THEN 1 ELSE '0' END --门店 UPDATE imp_member SET comp_id = dbo.FNCompId('002') UPDATE imp_member_card SET comp_id = dbo.FNCompId('002') UPDATE A SET A.card_type_id = B.id FROM imp_member_card AS A,imp_card_type AS B WHERE A.cardName + '['+discount+']'= B.name SELECT * FROM imp_card_type SELECT * FROM imp_card_type UPDATE imp_member SET Birthday_Type = 'G' UPDATE imp_member SET Birthday_Type = 'L' WHERE 生日 LIKE '%农历%' UPDATE imp_member SET Birthday = REPLACE(REPLACE(生日 , '农历','9999-') , '阳历','9999-') SELECT * FROM imp_member --门店 -- 余额 UPDATE imp_member_card SET FBalance = cast(balance as float) -- delete TMemberCardType WHERE FId > 100 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 id ,name,name,1,2,0,0,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 FROM imp_card_type UPDATE TMemberCardType SET FAllowRchg = 1 WHERE FId IN(SELECT id FROM imp_card_type) UPDATE TMemberCardType SET FAllowSale = 1 WHERE FId IN(SELECT id FROM imp_card_type) UPDATE TMemberCardType SET FEnabled = 1 WHERE FId IN(SELECT id FROM imp_card_type) UPDATE TMemberCardType SET FValidityPeriod = 100 WHERE FId IN(SELECT id FROM imp_card_type) UPDATE TMemberCardType SET FValidityPerioduNIT = 1 WHERE FId IN(SELECT id FROM imp_card_type) UPDATE TMemberCardType SET FExpiredDate = null WHERE FId IN(SELECT id FROM imp_card_type) UPDATE TMemberCardType SET FDeposit = 0,FDefaultMemo = '' WHERE FId IN(SELECT id FROM imp_card_type) 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 IN(SELECT id FROM imp_card_type) --AND C.FNo IN('000','002') AND NOT EXISTS(SELECT TOP 1 1 FROM TMemberCardTypeSub AS B WHERE B.FCompId = C.FId AND B.FCardTypeId = I.FId) UPDATE TMemberCardType SET FMaterial = 2 UPDATE imp_member SET FMemNO = 'MH' + FMemNo WHERE FMemNo IN(SELECT FMemNO FROM TMember) UPDATE imp_member_card SET FCardNo = 'MH' + FCardNo WHERE FCardNo IN(SELECT FCardNo FROM TMember) SELECT * FROM imp_member WHERE FNewMemId != FMemId AND FMemo != '' UPDATE imp_member SET FMemNO = FMobile WHERE ISNULL(FMemNo,'') = '' 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 mem_id AS FMemId, mem_no AS FMemNo, name AS FName, dbo.FNGetFirstPinYin(name), 0 AS FTypeId, comp_id AS comp_id, cast(create_date as datetime) AS FCreateDate, gender AS FGender, Birthday_Type AS FBirthdayType, Birthday AS FBirthday, '' AS FTelephone, ISNULL(Mobile,'') AS FMobilePhone, '' AS FQQ, '' AS FWeChat, '' AS FIdCard, '' AS FEmail, '' AS FAddress, 0 AS FProId, '' AS FCPW, '' AS FQPW, 0 AS FChargeEmpId, ISNULL( Point,0) AS FPoint, 1 AS FRecvConsSMS, 1 AS FRecvBulkSMS, ISNULL('','') AS FMemo, '' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5 from imp_member select * from imp_member INSERT TMemberPointHist(FId,FMemId,FTime,FCardId,comp_id,FBillType,FBizType,FTransId,FTransNo,FInAmount,FOutAmount,FBalance,FMemo,FRecordTime) SELECT dbo.FNNewId(),A.FMemId,getdate(),0,1,'DR','Import',0,'',FNewPoint,0,FNewPoint,'',getdate() FROM imp_member AS A WHERE FNewPoint != 0 SELECT * FROM imp_member WHERE FMemId != FNewMemId /* SELECT * FROM imp_member WHERE FMemId IN( SELECT FMemId,FMemNo,FName,FMobile,FGender,comp_id ,FBirthdayType ,FBirthday,FCreateDate,FPoint INTO #Temp FROM imp_member GROUP BY FMemId,FMemNo,FName,FMobile,FGender,comp_id ,FBirthdayType ,FBirthday,FCreateDate,FPoint ORDER BY SUM(1) DESC ) SELECT FMemNO,SUM(1) FROM TIMpmember WHERE FMemId = FNewMemId GROUP BY FMemNO HAVING(SUM(1) > 1) SELECT FMemId FROM #Temp GROUP BY FMemId HAVING(SUM(1)) > 1 SELECT * FROM TImpmEMBER WHERE FMobile = '18765015301' UPDATE imp_member SET FMemNo = '0000330' WHERE FMemId = 25463627 UPDATE imp_member SET FMemNo = '0000055' WHERE FMemId = 25006217 */ INSERT INTO TMemberCard( FCardId, FCardNo, FCardFaceNo, FTypeId, FValueType, FCompId, FMemId, FState, FCreateDate, FExpiredDate, FTotalTimes, FUsedTimes, FSaleCompId, FSaleBillId, FMemo) SELECT card_id AS FId, card_no AS FNo, card_no AS FFaceNo, card_type_id AS FTypeId, (SELECT FValueType FROM TMemberCardType WHERE FId = card_type_id) AS FValueType, comp_id AS comp_id, mem_id AS FMemId, 1 AS FState, create_date AS FCreateDate, expired_date AS FExpiredDate, ISNULL(0,0) AS FTotalTimes, 0 AS FUsedTimes, comp_id AS FSaleCompId, 0 AS FSaleBillId, ISNULL(memo,'') AS FMemo FROM imp_member_card SELECT * FROM imp_member WHERE FCardId IS NULL SELECT * FROM imp_member_card WHERE CardNo IS NOT NULL INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo) SELECT mem_id,dbo.FNNewId(),card_id AS FCardId,3,cast(balance as float),cast(balance as float),0,create_date,NULL AS FExpiredDate,'' FROM imp_member_card 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.mem_id,A.card_id,3,getdate(),A.card_type_id,A.comp_id,'DR','Import',0,'',cast(balance as float),0,cast(balance as float),0,getdate(),'导入' FROM imp_member_card 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 imp_member_card AS A WHERE FBalance2 != 0 AND FNewMemId IN(SELECT FMemId FROM TMember) INSERT TMemberCardAcctHist(FId,FMemId,FCardId,FAcctId,FTime,FCardTypeId,comp_id,FBillType,FBizType,FTransId,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo) select dbo.FNNewId(),A.FMemId,A.FCardId,10,getdate(),A.FCardTypeId,A.comp_id,'DR','Import',0,'',A.FBalance2,0,A.FBalance2,0,getdate(),'从盛传中导入' FROM imp_member_card AS A WHERE FBalance2 != 0 AND FNewMemId IN(SELECT FMemId FROM TMember) --疗程 SELECT * FROM imp_member_card WHERE card_kind = 'Course' DROP TABLE imp_item SELECT dbo.FNNewId() as id ,dbo.FNNewId() AS course_id, cardName AS name,case when types = '[]' THEN 2 ELSE 1 END AS calc_mode into imp_item FROM imp_member_card WHERE card_kind = 'Course' GROUP BY cardName,types DELETE TItem WHERE FId IN(SELECT id FROM imp_item) 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 id,name,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, I.name + '', I.name + '' + '' AS FName, '' AS FBriefCode, I.id AS FItemId, 0 AS FPackId, 1 AS FSequence, (SELECT TOP 1 FId FROM TBasicType WHERE FKey = 'CourseType') AS FTypeId, 1 AS FTimes, 0 AS FFreeTimes, 0 AS FDurable, 0 AS FValidityPeriodUnit, 0 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 I 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 C.FNo = '009' AND NOT EXISTS(SELECT TOP 1 1 FROM TItemSub AS B WHERE B.FCompId = C.FId AND B.FItemId = I.FId) AND C.FId IN(SELECT 1 UNION ALL SELECT comp_id FROM imp_company) SELECT * FROM imp_member_card WHERE card_kind = 'Course' UPDATE imp_member_card SET calc_mode = 1 WHERE card_kind = 'Course' UPDATE imp_member_card SET calc_mode = 2 WHERE card_kind = 'Course' AND types = '[]' UPDATE A SET A.card_type_id = b.course_id,a.item_id = b.id FROM imp_member_card AS A,imp_item AS B WHERE A.cardName = b.name SELECT COUNT(1) FROM imp_member_card WHERE expired_date is null UPDATE imp_member_card SET pur_times = totalTimes,free_times = totalFreeTimes WHERE card_kind = 'Course' UPDATE imp_member_card SET pur_times = 0,free_times = 0 WHERE card_kind = 'Course' AND calc_mode = 2 UPDATE imp_member_card SET used_pur_times = 0,used_free_times = 0 WHERE card_kind = 'Course' UPDATE imp_member_card SET adjust_price = 0 UPDATE imp_member_card SET adjust_price = cast(balance as float) / cast(totalTimes as float) where cast(totalTimes as float) > 0 UPDATE imp_member_card SET pur_amount = cast(balance as float ) WHERE card_kind = 'Course' INSERT TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FUsedPurTimes,FPurAmount,FFreeTimes,FFreeAmount,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice) SELECT card_id,mem_id,card_type_id,0,item_id,comp_id,pur_times,used_pur_times,pur_amount,free_times,used_free_times,create_date,expired_date,'DR.Import',0,0,0,'',calc_mode,adjust_price FROM imp_member_card AS A WHERE card_kind = 'Course' INSERT INTO TMemberCourseLog(FId,FMemId,FCardId,FPackId,FCourseId,FTime,FInPurTimes,FInFreeTimes,FOutPurTimes,FOutFreeTimes,FCompId,FBillType,FBizType,FBillId,FBillNo,FBillDetailId,FRecordTime) SELECT dbo.FNNewId(),mem_id,A.card_id AS FCardId,0, ISNULL(card_type_id,0),getdate(),pur_times,free_times,0,0,comp_id,'DR','Import',0,'',0,getdate() FROM imp_member_card AS A WHERE card_kind = 'Course' SELECT * FROM imp_member_card --欠款 ALTER TABLE TImpMemberArrear ADD comp_id BIGINT ALTER TABLE TImpMemberArrear ADD FMemId BIGINT ALTER TABLE TImpMemberArrear ADD FCardId BIGINT UPDATE A SET A.FMemId = MemId FROM TImpMemberArrear AS A UPDATE A SET A.FCardId = B.FCardId FROM TImpMemberArrear AS A,imp_member_card AS B WHERE A.MemID = B.MemId UPDATE TImpMemberArrear SET comp_id = dbo.FNCOmpId('006') INSERT TMemberArrear(FId,FMemId,FTime,comp_id,FContentType,FCardId,FBillType,FBizType,FTransId,FTransNo,FTransDetailId,FContentId,FArrear,FEmpId,FRepaid,FAcctArrear) SELECT dbo.FNNewId(),A.FMemId,getdate(),A.comp_id,'Account',A.FCardId,'DR_KK','DR_CardSale',0,单号,0,3,CAST(A.未还金额 AS FLOAT) ,0,0,0 FROM TImpMemberArrear AS A WHERE CAST(A.未还金额 AS FLOAT) > 0 --历史 ALTER TABLE imp_member_cons_hist ADD comp_id BIGINT ALTER TABLE imp_member_cons_hist ADD mem_id BIGINT ALTER TABLE Imp_Member_Rchg_Hist ADD comp_id BIGINT ALTER TABLE Imp_Member_Rchg_Hist ADD mem_id BIGINT UPDATE A SET A.mem_id = B.mem_id, A.comp_id = B.comp_id FROM imp_member_cons_hist AS A,imp_member AS B WHERE A.memberId = B.id UPDATE A SET A.mem_id = B.mem_id, A.comp_id = B.comp_id FROM imp_member_cons_hist AS A,imp_member AS B WHERE A.memberId = B.id SELECT * FROM imp_member_cons_hist SELECT * FROM imp_member_cons_hist_detail delete imp_member_cons_hist_detail ALTER TABLE imp_member_cons_hist ADD CONTENT VARCHAR(2000) SELECT * FROM TImpMemberRchgHist SELECT * FROM imp_member_cons_hist_detail WHERE skuid = 2125718 SELECT * FROM imp_member_cons_hist INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompID,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo) SELECT DBO.FNNewId(),A.mem_id,A.addTime,0,A.comp_id,'DR','Import',orderDisplayId,content,0,1,0,actualpayamount,isnull(employees,''),'' FROM imp_member_cons_hist AS A WHERE ISNULL(mem_id,0) != 0 SELECT memberId, UPDATE A SET A.content = B.FContent FROM imp_member_cons_hist AS A, ( SELECT orderId, STUFF( (SELECT ',' + skuname FROM imp_member_cons_hist_detail AS I WHERE I.orderId = B.orderId FOR XML PATH('')),1,1,'' ) AS FContent FROM imp_member_cons_hist AS B ) AS B WHERE A.orderId = b.orderId SELECT * FROM TMemberOldTransHist INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo) SELECT DBO.FNNewId(),A.mem_id,A.addTime,0,A.comp_id,'DR','Import',ordercode,cardName,0,1,0,actualpayamount,isnull(employees,''),'' FROM Imp_Member_Rchg_Hist AS A WHERE ISNULL(mem_id,0) != 0 --照片 SELECT * FROM TMemberPhoto INSERT TMemberPhoto(FMemId,FType,FImage,FImagePath,FChangeId) SELECT FMemId,1,NULL,REPLACE(FAvatar,'http://files.sentree.com.cn/photo/850621/',''),1 FROM imp_member WHERE ISNULL(FAvatar,'') != '' --员工 ALTER TABLE TImpEmployee ADD FPosId BIGINT SELECT * FROM TImpEmployee ALTER TABLE TImpEmployee ADD FPosName VARCHAR(100) ALTER TABLE TImpEmployee ADD FNo VARCHAR(20) ALTER TABLE TImpEmployee ADD FId BIGINT UPDATE TImpEmployee SET FId = dbo.FNNewId() UPDATE TImpEmployee SET FPosName = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(级别,'1',''),'2',''),'3',''),'添加此工位',''),'修改级别',''),'调店',''),'离职',''),' ',''),'复职','') INSERT TBasicType(FId,FNo,FKey,FName) SELECT dbo.FNNewId(),FPosName,'Position',FPosName FROM TImpEmployee GROUP BY FPosName INSERT TBasicTypeSub(FBasicTypeId,comp_id) SELECT A.FId,C.FId FROM TBasicType AS A,TCompany AS C WHERE A.FKey = 'Position' AND C.FId > 0 UPDATE A SET A.FPosId = B.FId FROM TImpEmployee AS A,TBasicType AS B WHERE A.FPosName = B.FName AND B.FKey = 'Position' UPDATE A SET A.FNo = B.comp_no + A.编号 FROM TImpEmployee AS A,imp_company AS B WHERE A.shopId = B.shopId INSERT INTO TEmployee(FId,FNo,FName,FEnLname,FEnFname,FNickname,FDeptId,FPosId,FTechTypeId,FBriefCode,FGender,FStature,FWeight,FNationPlace,FNation,FEducation,FMarital,FAddress,FTelephone,FMobilePhone,FQQ,FEmail,FIdCard,FBirthdayType,FBirthday,FCardNo,FPW,FBank,FBankCardNo,FSSNo,FHCNo,FLinkMan,FLinkManTel,FLinkManAddr,FIsManager,FAllowBooking,FContractType,FState,FCreatorId,FCreateDate,FEntryDate,FExpiredDate,FLeaveDate,FPrice,FTags) SELECT FId,FNo,姓名,FEnLname = '',FEnFname = '',FNickname = 姓名,FDeptId = 0, FPosId,FTechTypeId = 0,FBriefCode = DBO.FNGetFirstPinYin(姓名),FGender = CASE WHEN 性别 = '男' THEN 1 ELSE 0 END, FStature = 0,FWeight = 0,FNationPlace = 0,FNation = 0,FEducation = '',FMarital = '',FAddress = '', FTelephone = '',FMobilePhone = 手机,FQQ = '',FEmail = '',FIdCard = 身份证号,FBirthdayType = CASE WHEN 生日 LIKE '农历' THEN 'L' ELSE 'G' END, FBirthday = RIGHT(生日,10), FCardNo = '',FPW ='',FBank = '',FBankCardNo = '',FSSNo = '',FHCNo ='',FLinkMan = '', FLinkManTel = '',FLinkManAddr = '' ,FAllowSign = 0,FAllowBooking = 1,FContractType = '', FState = 1,FCreatorId = 0,FCreateDate = GETDATE(),FEntryDate = 入职日期,FExpiredDate = null,FLeaveDate = null, FPrice = 0,FTags = '' FROM TImpEmployee WHERE 状态 = '在职' UPDATE TEmployee SET FBirthday = null where FBirthday = '1900-01-01' INSERT TEmployeeSub(comp_id,FEmpId,FSerialNo) SELECT C.comp_id,A.FId,A.编号 FROM TImpEmployee AS A,imp_company AS C WHERE A.ShopId = C.ShopId --产品 ALTER TABLE TImpGoods ADD FId BIGINT ALTER TABLE TImpGoods ADD FNo VARCHAR(50) ALTER TABLE TImpGoods ADD FUnitId BIGINT UPDATE TIMpGoods SET FNo = no INSERT TBasicType(FId,FNo,FKey,FName) SELECT dbo.FNNewId(),unit,'GoodsUnit',unit FROM TImpGoods WHERE unit NOT IN(SELECT FName FROM TBasicType WHERE FKey = 'GoodsUnit') AND Unit != '' GROUP BY unit UPDATE TImpGoods SET unit = '瓶' WHERE unit = '' INSERT TBasicTypeSub(FBasicTypeId,comp_id) SELECT A.FId,C.FId FROM TBasicType AS A,TCompany AS C WHERE A.FKey = 'GoodsUnit' AND C.FId > 0 AND A.FId NOT IN(SELECT FBasicTypeId FROM TBasicTypeSub) UPDATE A SET A.FUnitId = B.FId FROM TImpGoods AS A,TBasicType AS B WHERE A.unit = B.FName AND B.FKey = 'GoodsUnit' UPDATE A SET A.FNo = B.comp_no + A.no FROM TIMpGoods AS A,imp_company AS B WHERE A.shopId = B.shopId UPDATE TImpGoods SET FNo = name WHERE FNo In( SELECT FNo FROM TImpGoods WHERE status = 1 GROUP BY FNo HAVING(SUM(1) > 1) ) INSERT INTO TGoods(FId,FNo,FName,FNoOfPad,FTypeId,FBriefCode,FUnitId,FSalePrice,FPurCostPrice,FSaleCostPrice,FConsCostPrice,FValuationMode,FBarCode,FEnabled,FSpecification,FPurUnitId,FConsUnitId,FSupplierId,FStoreId,FConsStoreId,FSaleStoreId,FMaxStock,FMinStock,FPeriodEnabled,FShelfLife,FDctId,FPointMode,FPointValue,FDeptId,FIsSale,FUnitLock,FDescription,FCustom1,FCustom2,FCustom3) SELECT id,FNo,name,FNo,FTypeId = 0,dbo.FNGetFirstPinYin(name), FUnitId,FSalePrice = cast(salePrice as float),FPurCostPrice = cast(inprice as float),FSaleCostPrice = 0,FConsCostPrice = 0, FValuationMode = 0,FBarCode = 0,FEnabled = 1,FSpecification = '', FPurUnitId = 0,FConsUnitId = 0,FSupplierId = 0,FStoreId = 0,FConsStoreId= 0,FSaleStoreId= 0, FMaxStock= 0,FMinStock= 0,FPeriodEnabled= 0,FShelfLife= 0,FDctId= 0,FPointMode= 0,FPointValue= 0, FDeptId= 0,FIsSale = 1,FUnitLock= 0,FDescription= '',FCustom1 = '',FCustom2 = '',FCustom3 = '' FROM TImpGoods WHERE status = 1 INSERT INTO TGoodsMultiUnit(FId,FGoodsId,FUnitType,FUnitId,FSequence,FConvDir,FConvRate,FSalePrice,FPurCostPrice,FSaleCostPrice,FConsCostPrice,FBarCode,FUnitLock) SELECT dbo.FNNewId(),FId,1,FUnitId,1,1,1,FSalePrice,FPurCostPrice,FSaleCostPrice,FConsCostPrice,FBarCode,FUnitLock FROM TGoods DELETE TGoodsMultiUnit INSERT TGoodsSub(FId,FGoodsId,comp_id) SELECT dbo.FNNewId(),A.ID,C.comp_id FROM TImpGoods AS A,imp_company AS C WHERE A.shopId = c.shopId AND status = 1 --项目 SELECT * FROM TImpItem --预约 SELECT barberName FROM TImpBooking GROUP BY barberName --员工 ALTER TABLE TImpBooking ADD FEmpId BIGINT UPDATE A SET A.FEmpId = B.FId FROM TImpBooking AS A,TEmployee AS B WHERE A.barberName = B.FName --项目 ALTER TABLE TImpBooking ADD FItems VARCHAR(1000) UPDATE A SET A.FItems = B.FId FROM TImpBooking AS A,TBasicType AS B WHERE B.FKey = 'BookingItem' AND REPLACE(categoryName,'类','') = B.FName OR(categoryName = '洗吹类' AND B.FName = '洗发') SELECT * FROM TImpBooking WHERE FItems IS NULL AND ISNULL(categoryName,'') != '' SELECT * FROM TBasicType WHERE FKey = 'BookingItem' SELECT * FROM TImpBooking --会员 ALTER TABLE TImpBooking ADD FCustName VARCHAR(1000),FCustMobile VARCHAR(1000),FCustGender INT UPDATE TImpBooking SET FCustName = custName,FCustMobile = memmobile,FCustGender = case when sex = 'M' then 1 else 0 end --门店 ALTER TABLE TImpBooking ADD comp_id BIGINT UPDATE TImpBooking SET comp_id = 1 -- ALTER TABLE TImpBooking ADD FSource VARCHAR(100) UPDATE TImpBooking SET FSource = 'WeChat' WHERE channel = 1 UPDATE TImpBooking SET FSource = 'Manual' WHERE channel != 1 ALTER TABLE TImpBooking ADD FStatus INT UPDATE TImpBooking SET FStatus = 2 INSERT INTO TBooking(FId,comp_id,FCreationTime,FBookingTime,FDuration,FEmpId,FCustName,FCustGender,FCustMobile,FItems,FMemo,FSource,FStatus,FReason,FRemindStep,FUnifiedRemind,FConfirmTime,FFinishTime,FCreatorId) SELECT id,comp_id,FCreateTime,FBookingTime,0,FEmpId,FCustName,FCustGender,FCustMobile,ISNULL(FItems,''),'',FSource,FStatus,'',0,0,FCreateTime,NULL,1 FROM TImpBooking