USE ZhangZhi_ZuoMi SELECT count(1) FROM MemCard WITH(NOLOCK) WHERE CardCode NOT IN(SELECT CardCode FROM mem_fund) --会员 ALTER TABLE MemCard ADD FMemId BIGINT NOT NULL DEFAULT 0 ALTER TABLE MemCard ADD FMemNo VARCHAR(50) NOT NULL DEFAULT '' ALTER TABLE MemCard ADD FName VARCHAR(50) NOT NULL DEFAULT '' ALTER TABLE MemCard ADD FGender INT NOT NULL DEFAULT 0 ALTER TABLE MemCard ADD FMobile VARCHAR(50) NOT NULL DEFAULT '' ALTER TABLE MemCard ADD FMemo VARCHAR(1000) DEFAULT '' ALTER TABLE MemCard ADD FArrear DECIMAL(18,6) DEFAULT 0 ALTER TABLE MemCard ADD FPoint DECIMAL(18,6) DEFAULT 0 ALTER TABLE MemCard ADD FBirthday DATETIME ALTER TABLE MemCard ADD FBirthdayType CHAR NOT NULL DEFAULT '' ALTER TABLE MemCard ADD FCreateDate DATETIME ALTER TABLE MemCard ADD FExpiredDate DATETIME ALTER TABLE MemCard ADD FCompId BIGINT DEFAULT 0 ALTER TABLE MemCard ADD FDeleted BIT NOT NULL DEFAULT 0 ALTER TABLE MemCard ADD FPassword VARCHAR(1000) DEFAULT '' ALTER TABLE MemCard ADD FCardNo VARCHAR(50) NOT NULL DEFAULT '' ALTER TABLE MemCard ADD FCardTypeId BIGINT NOT NULL DEFAULT 0 ALTER TABLE MemCard ADD FBalance DECIMAL(18,6) NOT NULL DEFAULT 0 ALTER TABLE MemCard ADD FRemainTimes INT NOT NULL DEFAULT 0 ALTER TABLE MemCard ADD FCardId BIGINT NOT NULL DEFAULT 0 ALTER TABLE MemCard ADD FCardMemo VARCHAR(1000) NOT NULL DEFAULT '' ALTER TABLE MemCard ADD FCardState INT NOT NULL DEFAULT 0 SELECT * FROM CardLevel SELECT * FROM jinan_xiu..TCompany SELECT * FROM MemCard UPDATE MemCard SET FCardTypeId = abs( CAST( CAST(CAST(CardTypeGUID AS UNIQUEIDENTIFIER) AS BINARY(16)) AS BIGINT)) ---卡类别 INSERT TMemberCardType(FId,FNo,FName,FValueType,FMaterial,FPrice,FAcctId,FDeposit,FAcctId2,FDeposit2,FAcctId3,FDeposit3,FTimes,FAlertBalance,FMinRchgAmt,FValidityPeriod,FValidityPeriodUnit,FAllowSale,FAllowRchg,FEnabled,FOrder,FSalePointMode,FSalePointValue,FRchgPointMode,FRchgPointValue) SELECT FId = 20000+ID, FNo = LevelName, FName = LevelName, 1 AS FValueType, 2 AS FMaterial, 0 AS FPrice, 3 AS FAcctId, 0 AS FDeposit, 0 as FAcctId2, 0 AS FDeposit2, 0 AS FAcctId3, 0 AS FDeposit3, 0 AS FTimes, 0 AS FAlertBalance, 0 AS FMinRchgAmt, 100 AS FValidityPeriod, 1 AS FValidityPeriodUnit, 1 AS FAllowSale, 1 AS FAllowRchg, 1, 1, 0 AS FSalePointMode, 0 AS FSalePointValue, 0 AS FRchgPointMode, 0 AS FRchgPointValue FROM CardLevel SELECT * FROM jinan_xiu..TCompany SELECT * FROM jinan_xiu..TMemberCardTypeCross SELECT * FROM jinan_xiu..TMemberCardTypeCross 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 C.FNo IN('000','001') AND NOT EXISTS(SELECT TOP 1 1 FROM TMemberCardTypeSub AS B WHERE B.FCompId = C.FId AND B.FCardTypeId = I.FId) UPDATE TMemberCardTypeSub SET FCompID = DBO.FNCompId('007') WHERE FCompId = dbo.FNCompId('006') AND FCardTypeID IN(SELECT FId FROM TMemberCardType WHERE FNo like 'TL%') SELECT * FROM MemCard UPDATE A SET A.FCardTypeId = 20000 + levelid FROM MemCard AS A UPDATE A SET A.FCardTypeId = B.FCardTypeId FROM JINAN_XIU..TMemberCardAcctHist AS A,MemCard AS B WHERE A.FCardId = B.FCardId UPDATE A SET A.FAllowSale = B.FAllowSale, A.FAllowRchg = B.FAllowRchg FROM _sweet_laodian..TMemberCardType AS B,TMemberCardType AS A WHERE A.FId = B.FId UPDATE TMemberCardType SET FAllowSale = 1,FAllowRchg = 1 WHERE FId <30000 AND FId > 20000 SELECT * FROM TMemberCardType --会员资料 SELECT * FROM MemCard WHERE GuestName IS NULL -- 标记为删除 UPDATE MemCard SET FDeleted = 0 UPDATE MemCard SET FDeleted = 1 WHERE cardid = '0000' AND Name = '散客消费' --门店 UPDATE MemCard SET FCompId = dbo.FNCompId('001') --会员ID,+100000 UPDATE MemCard SET FMemId = 20000 + ID --姓名 UPDATE MemCard SET FName = ISNULL(ISNULL(Name,Mobile),CardId) --电话 UPDATE MemCard SET FMobile = ISNULL(Mobile,'') --性别 UPDATE MemCard SET FGender = CASE WHEN sex = -1 THEN 1 ELSE 0 END --CreateDate --卡 --卡ID UPDATE MemCard SET FCardId = 30000 + ID --卡号 UPDATE MemCard SET FCardNO = CardId where CardId is not null UPDATE MemCard SET FMemno = FCardNo --余额 UPDATE MemCard SET FBalance = Money --积分 UPDATE MemCard SET FPoint = Point --开卡日期 ALTER TABLE MemCard ALTER COLUMN CreateTime VARCHAR(100) UPDATE MemCard SET FCreateDate = LEFT(CreateTime,4) + '-' + SUBSTRING(CreateTime,5,2) + '-' + SUBSTRING(CreateTime,7,2) --有效期 UPDATE MemCard SET FExpiredDate = dateadd(year,100,FCreateDate) --密码 --UPDATE MemCard SET FPassword = ISNULL(CardPsw,'') --备注 UPDATE MemCard SET FCardMemo = isnull(remark,'') SELECT * FROM MemCard UPDATE MemCard SET FCardState = 1 UPDATE MemCard set FCardState = 4 WHERE state != 1 --处理重复的卡号 SELECT * FROM TMEMBER INSERT 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) as fcode, 0 AS FTypeId, FCompId AS FCompId, FCreateDate , FGender AS FGender, 'G' AS FBirthdayType, FBirthday AS FBirthday, '' AS FTelephone, ISNULL(FMobile,'') AS FMobilePhone, '' AS FQQ, '' AS FWeChat, '' AS FIdCard, '' AS FEmail, '' AS FAddress, 0 AS FProId, ISNULL('','') AS FCPW, '' AS FQPW, 0 AS FChargeEmpId, ISNULL( FPoint,0) AS FPoint, 1 AS FRecvConsSMS, 1 AS FRecvBulkSMS, ISNULL('','') AS FMemo, '' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5 -- into #t from MemCard WHERE FDeleted = 0 SELECT FMemId,sum(1) FROM #t 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, 0 AS FTotalTimes, 0 AS FUsedTimes, FCompId AS FSaleCompId, 0 AS FSaleBillId, FCardMemo AS FMemo FROM MemCard WHERE FDeleted = 0 update TMemberCardAccount SET FExpiredDate = null WHERE FCardTypeId IS NOT NULL 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 MemCard AS A WHERE FDeleted = 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,3,getdate(),A.FCardTypeId,A.FCompId,'DR','Import',0,'',A.FBalance,0,A.FBalance,0,getdate(),'从魅秀中导入' FROM MemCard AS A WHERE FDeleted = 0 UPDATE TMemberCardAcctHist SET FMemo = '' SELECT * FROM TImpTransLog WHERE 客户编号 = 'A020935' update A SET A.FMemId SELECT * FROM TMemberCard WHERE FId = 5494058162892437466 UPDATE A SET A.FExpiredDate = B.FExpiredDate FROM TMemberCard AS A,MemCard3 AS B WHERE A.FCardId = B.FCardId SELECT * FROM MemCard3 UPDATE A SET A.FMemo = B.Rem FROM TMemberCard AS A,MemCard3 AS B WHERE A.FCardId = B.FCardId AND B.Rem IS NOT NULL SELECT * FROM TMemberCardType UPDATE TMemberCardType SET FId = FNo + 1000 WHERE FId > 0 UPDATE TMemberCard SET FTypeId = 0 DELETE TMemberCardTypeSUB UPDATE A SET A.FTypeId = B.CType + 1000 FROM TMemberCard AS A,MemCard3 AS B WHERE A.FCardId = B.FCardId UPDATE MemCard3 SET FCardTypeId = CType + 1000 SELECT * FROM TMemberCard WHERE FMemo != '' delete MemCard3 where CUSTNO IN(SELECT CUSTNO FROM MemCard2) ALTER TABLE mem_fund ADD FCompId BIGINT UPDATE mem_fund SET FCompId = jinan_xiu.dbo.FNCompId('007') WHERE mach = '1001' UPDATE mem_fund SET FCompId = jinan_xiu.dbo.FNCompId('008') WHERE mach = '1002' UPDATE mem_fund SET FCompId = jinan_xiu.dbo.FNCompId('009') WHERE mach = '1003' UPDATE mem_fund SET FCompId = jinan_xiu.dbo.FNCompId('010') WHERE mach = '1005' DELETE TMemberOldTransHist INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo) SELECT dbo.FNNewId(),M.FMemId,fund_time,M.FCardId,A.FCompId,'DR',CASE WHEN fund_Type = 1 THEN '充值' ELSE '消费' END,'',a.mem,0,0,money ,'','','' FROM mem_fund AS A , MemCard AS M WHERE A.mem_id = M.mem_id SELECT * FROM CardByCount WHERE mem_id = '203761' SELECT dbo.FNNewId() AS item_id,dbo.FNnewId()AS course_id ,Msg AS item_name,msg as item_no INTO imp_item FROM CardByCount GROUP BY Msg --疗程 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,FDisplay) SELECT item_id,item_name,item_name,item_name,item_name,0,dbo.FNGetFirstPinYin(item_name),'',1,1,1,'','','',1,0,0,0,0,1,0,0,1,1 FROM imp_item 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 I.FId IN(SELECT item_id FROM imp_item) AND C.FNo IN('001') 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, item_no, item_name , dbo.FNGetFirstPinyin(item_name) AS FBriefCode, item_id AS FItemId, 0 AS FPackId, 1 AS FSequence, 0 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 WHERE item_id IN(SELECT item_id FROM mem_item) --疗程 ALTER TABLE CardByCount ADD FCardTypeId BIGINT ALTER TABLE CardByCount ADD FItemId BIGINT ALTER TABLE CardByCount ADD FRemainTimes INT ALTER TABLE CardByCount ADD FPurTimes INT ALTER TABLE CardByCount ADD FUsedTimes INT ALTER TABLE CardByCount ADD FPurAmount DECIMAL(18,6) ALTER TABLE CardByCount ADD FAdjustPrice DECIMAL(18,6) ALTER TABLE CardByCount ADD FCreateDate DATETIME ALTER TABLE CardByCount ADD FExpiredDate DATETIME ALTER TABLE CardByCount ADD FCompId BIGINT ALTER TABLE CardByCount ADD FCardId BIGINT ALTER TABLE CardByCount ADD FMemId BIGINT ALTER TABLE CardByCount ADD FMemo VARCHAR(1000) UPDATE CardByCount SET FCardId = dbo.FNNewId(),FPurAmount = 0 UPDATE A SET A.FCardTypeId = B.course_id, A.FItemId = B.item_id FROM CardByCount AS A,imp_item AS B WHERE B.item_name = A.Msg UPDATE CardByCount SET FPurAMOUNT = Money UPDATE CardByCount SET FPurTimes = TotalCount UPDATE CardByCount SET FUsedTimes = TotalCount - OverCount UPDATE CardByCount SET FCreateDate = LEFT(CAST(CreateTime AS VARCHAR),4) + '-' + SUbstring(CAST(CreateTime AS VARCHAR),5,2) + '-' + SUBSTRING(CAST(CreateTime AS VARCHAR),7,2) UPDATE CardByCount SET FAdjustPrice = Money - FPurTimes select * from CardByCount SELECT * FROM MemCard UPDATE A SET A.FMemId = B.FMemId, A.FCompID = b.fcompid FROM CardByCount AS A,MemCard AS B WHERE A.CardId = B.CardId 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,FCardTypeId,0,FItemId,FCompId,FPurTimes,FUsedTimes,FPurAmount,0,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,'导入',1,FAdjustPrice FROM CardByCount AS A WHERE OverCount > 0 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(FCardTypeId,0),getdate(),FPurTimes,0,FUsedTimes,0,FCompId,'DR','Import',0,'',0,getdate() FROM CardByCount AS A use jinan_xiu UPDATE TMemberCard SET FCardNo = REPLACE(FCardNo,' ','') UPDATE TMember SET FMemNo = REPLACE(FMemNo,' ','') UPDATE TMember SET FName = REPLACE(FName,' ','') UPDATE TMember SET FMobilePhone = REPLACE(FMobilePhone,' ','') UPDATE TMemberCard SET FMemo = REPLACE(FMemo,' ','') WHERE FMemId IN(SELECT FMemID FROM jinan_fuhang..MemCard) UPDATE TItem SET FNo = REPLACE(FNo,' ','') UPDATE TItem SET FName = REPLACE(FName,' ','') --充值历史 SELECT * FROM RechargeLog ALTER TABLE RechargeLog ADD FCompId BIGINT UPDATE A SET A.FCompId = B.FCompId FROM RechargeLog AS A,MemCard AS B WHERE A.MemId = B.Id ALTER TABLE RechargeLog ALTER COLUMN CreateTime VARCHAR(100) INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo) SELECT dbo.FNNewId(),20000+MemId,LEFT(CreateTime,4) + '-' + SUBSTRING(CreateTime,5,2) + '-' + SUBSTRING(CreateTime,7,2),30000+MemId,A.FCompId, 'DR','Import',ISNULL(OrderCode,''),Remark,Money,1,Money,Money,'','' FROM RechargeLog AS A WHERE FCompId IS NOT NULL --消费历史 SELECT * FROM OrderLog ALTER TABLE OrderLog ADD FCompId BIGINT ALTER TABLE OrderLog ALTER COLUMN CreateTime VARCHAR(100) UPDATE A SET A.FCompId = B.FCompId FROM OrderLog AS A,MemCard AS B WHERE A.MemId = B.Id INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo) SELECT dbo.FNNewId(),20000+MemId,LEFT(A.CreateTime,4) + '-' + SUBSTRING(CreateTime,5,2) + '-' + SUBSTRING(CreateTime,7,2),30000+MemId,A.FCompId, 'DR','Import',ISNULL(A.OrderCode,''), B.GoodsName,B.Price,B.Number,B.DiscountPrice,B.DiscountPrice,'','' FROM OrderLog AS A,OrderDetail AS B WHERE A.OrderCode = B.OrderCode SELECT A.OrderCode, A.OrderType,A.MemId,A.CardId,A.MemName,A.TotalNumber,A.TotalMoney,A.DiscountMoney,A.CreateTime, B.GoodsCode,B.GoodsName,B.DetailType,B.Price,B.DiscountPrice,B.Number FROM OrderLog AS A,OrderDetail AS B WHERE A.OrderCode = B.OrderCode