You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sql-tools/Import/美顾问.sql

319 lines
11 KiB

1 year ago
use YangQuan_YiHaoTaiGu_MGW
select m.MemberCode,m.MemberName,m.IDCard,m.Address,m.ExpiredDate,m.Constellation,m.Email,m.Hobby,m.CarType,m.FixTelephone,m.QQNumber,m.Professional,m.BloodType,m.Introducer,m.BodyHeight,m.BodyWeight,m.AddDate,m.Gender,m.Birthday,m.LunarBirthday,m.Zodiac,m.Telephone,m.Remark,m.MemberImage,m.CardCode,m.CardID,m.Password,m.CreateTime,m.Member_ID,m.MemberGrade_ID,m.Status,m.FFlag,m.UID,m.GroupID,m.BirthType,m.BirthYear,m.BirthMonth,m.BirthDays,m.BirthDate,m.OwnerID,m.ParentID,m.OldCardCode,m.OldCardID,m.CardRemark,m.CardNum,m.CardStatus,m.Operater_Name,m.CardOpener,m.OwnDesigner,m.OwnAdviser
,ma.DebtsAmount,ma.StoreTotal,ma.OffersTotal,ma.Balance,ma.Overdraft,ma.OffersScale,ma.StoreTimes,ma.ConsumeTimes,ma.ConsumeTotal,ma.DrawFee,ma.DebtTotal,ma.DebtTimes,ma.RepayTotal,ma.RepayTimes,ma.CardConsume,ma.CashPayConsume,ma.FPresentedBalance,ma.InitScore,ma.Score,ma.StoreType,ma.GroupID AS GroupID_A,ma.ScoreTimes
,mg.GradeName,cs.ShopName,isnull(mw.CardCode,'') as OwnerMemberCode
INTO TImpMember
from
(select top 99999 * from b866_Member m where 1=1 and m.FFlag=0 and m.UID in(3601) and m.UID=3601 and Member_ID not in(select top 0 Member_ID from b866_Member m where 1=1 and m.FFlag=0 and m.UID in(3601) and m.UID=3601 order by m.AddDate Desc,m.Member_ID desc) order by m.AddDate Desc,m.Member_ID desc) m
left join b866_Member mw on m.OwnerID=mw.Member_ID
left join b866_MemberAccount ma on m.Member_ID=ma.Member_ID
left join b866_MemberGrade mg on m.MemberGrade_ID=mg.MemberGrade_ID
left join dbo.b866_ClientSys cs on cs.PlatID=m.UID order by m.AddDate Desc,m.Member_ID desc
use YangQuan_YiHaoTaiGu
SELECT * FROM TImpMemberCard WHERE <EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> = '3601MD-2014090220561100001843'
SELECT * FROM TImpMember WHERE Member_Id = '3601MD-2014090220561100001843'
SELECT * FROM TImpMemberCourse
SELECT * FROM TImpMember
WHERE Member_Id NOT IN(select <EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> FROM TImpMemberCard)
DELETE TImpMemberCard
DELETE TImpMemberCourse
SELECT * FROM
TImpMember WHERE FMobile = '18258203875'
SELECT
* FROM TImpMember WHERE Member_Id = '3601MD-2014090116493100000220'
SELECT
* FROM TImpMemberCard WHERE <EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> = '3601MD-2014090116493100000220'
SELECT <EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> FROM TImpMemberCard
GROUP BY <EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
HAVING SUM(1) > 1
--
ALTER TABLE TImpMember ADD FDeleted BIT
ALTER TABLE TImpMember ADD FState INT
ALTER TABLE TImpMember ADD FMemId BIGINT
ALTER TABLE TImpMember ADD FCardId BIGINT
ALTER TABLE TImpMember ADD FMemNo VARCHAR(50)
ALTER TABLE TImpMember ADD FName VARCHAR(50)
ALTER TABLE TImpMember ADD FMobile VARCHAR(50)
ALTER TABLE TImpMember ADD FBirthday DATETIME
ALTER TABLE TImpMember ADD FBirthdayType CHAR
ALTER TABLE TImpMember ADD FCompId BIGINT
ALTER TABLE TImpMember ADD FMemo VARCHAR(2222)
ALTER TABLE TImpMember ADD FCreateDate DATETIME
ALTER TABLE TImpMember ADD FPoint DECIMAL(18,6)
ALTER TABLE TImpMember ADD FBalance DECIMAL(18,6)
ALTER TABLE TImpMember ADD FGender INT
ALTER TABLE TImpMember ADD FExpiredDate DATETIME
ALTER TABLE TImpMemberCard ADD FCardId BIGINT
ALTER TABLE TImpMemberCard ADD FMemId BIGINT
ALTER TABLE TImpMemberCard ADD FCardNo VARCHAR(200)
ALTER TABLE TImpMemberCard ADD FCardTypeID BIGINT
ALTER TABLE TImpMemberCard ADD FCompId BIGINT
ALTER TABLE TImpMemberCard ADD FMemo VARCHAR(2222)
ALTER TABLE TImpMemberCard ADD FCreateDate DATETIME
ALTER TABLE TImpMemberCard ADD FPoint DECIMAL(18,6)
ALTER TABLE TImpMemberCard ADD FBalance DECIMAL(18,6)
ALTER TABLE TImpMemberCard ADD FBalance2 DECIMAL(18,6)
ALTER TABLE TImpMemberCard ADD FGender INT
ALTER TABLE TImpMemberCard ADD FExpiredDate DATETIME
ALTER TABLE TImpMemberCard ADD FState INT
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 = dbo.FNNewId(),<EFBFBD>ײ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD>ײ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,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 TImpMemberCard
GROUP BY <EFBFBD>ײ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DELETE TMemberCardTypeSub
INSERT INTO TMemberCardTypeSub(FId,FCompId,FCardTypeId,FAllowSale,FAllowRchg,FEnabled)
SELECT dbo.FNNewId(),C.FId,I.FID,1,1,1
FROM TMemberCardType AS I,TCompany AS C
WHERE I.FId > 0
AND C.FId > 0
SELECT * FROM TImpMember
WHERE GradeName = '5999<EFBFBD><EFBFBD>Ⱦ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
UPDATE TImpMember SET FMemId = dbo.FNNewId() WHERE FMemId IS NULL
UPDATE TImpMember SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL
UPDATE TImpMember SET FName = ISNULL(MemberName,'')
UPDATE TImpMember SET FMobile = ''
UPDATE TImpMember SET FMobile = Telephone WHERE LEN(Telephone) = 11
UPDATE TImpMember SET FBirthday = Birthday
UPDATE TImpMember SET FBirthdayType = 'G'
UPDATE TImpMember SET FGender = CASE WHEN Gender = '<EFBFBD><EFBFBD>' THEN 1 ELSE 0 END
UPDATE TImpMember SET FCreateDate = AddDate
UPDATE TImpMember SET FExpiredDate = ExpiredDate
UPDATE TImpMember SET FMemo = Remark
UPDATE TImpMember SET FMemNo = CardCode
UPDATE TImpMember SET FMemNo = FMobile + FName WHERE FMemNo = ''
UPDATE TImpMember SET FState = 1
UPDATE TImpMember SET FState = 4 WHERE CardStatus != 0
UPDATE TImpMember SET FCompId = 1
UPDATE A
SET A.FCardTypeId = B.FId
FROM TImpMemberCard AS A,TMemberCardType AS B
WHERE A.<EFBFBD>ײ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> = B.FName
UPDATE TImpMemberCard SET FCreateDate = <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
UPDATE TImpMemberCard SET FExpiredDate = <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
UPDATE TImpMemberCard SET FCompId = 1
UPDATE TImpMemberCard SET FState = 1
UPDATE TImpMember
SELECT * FROM TIMpMember WHERE FMobile = '18203438158'
SELECT * FROM TIMpMemberCard WHERE <EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> = '3601md-wx16062813241500000047'
SELECT * FROM TIMpMember wherE Status = 3
SELECT FMemNo FROM TImpMember
wherE Status != 3
GROUP BY FMemNo
HAVING SUM(1) > 1
SELECT * FROM TImpMember WHERE FMemNO = ''
UPDATE TImpMember SET FMemNO = REPLACE(Member_ID,'3601MD-','')
WHERE FMemNO = ''
UPDATE TImpMemberCard SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL
UPDATE A
SET A.FCardNo = B.FMemNO
FROM TImpMemberCard AS A,TImpMember AS B
WHERE A.<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> = B.Member_Id
UPDATE A
SET A.FMemId = B.FMemId
FROM TImpMemberCard AS A,TImpMember AS B
WHERE A.<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> = B.Member_Id
ALTER TABLE TImpMemberCard ADD FMemIndex INT
ALTER TABLE TImpMemberCard ADD FCardIndex INT
SELECT FCardNo FROM TImpMemberCard
GROUP BY FCardNo
HAVING SUM(1) > 1
UPDATE TImpMemberCard SET FMemIndex = 0;
UPDATE TImpMemberCard SET FCardIndex = 0;
UPDATE TImpMemberCard SET FBalance = <EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE TImpMemberCard SET FBalance2 = <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ALTER TABLE TImpMemberCard ALTER COLUMN <EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> VARCHAR(100)
CREATE INDEX IX_TImpMemberCard_CardNo ON TImpMemberCard(FCardNo)
CREATE INDEX IX_TImpMemberCard_<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ON TImpMemberCard(<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
UPDATE A
SET A.fcARDiNDEX = (SELECT COUNT(1) FROM TImpMemberCard AS B WHERE B.<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> = A.<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> AND B.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD> > A.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD> )
FROM TImpMemberCard AS A
UPDATE A
SET A.FCardNo = A.FCardNo + '_' + CAST(A.FCardIndex + 1 AS VARCHAR)
FROM TImpMemberCard AS A
WHERE A.FCardIndex > 0
select * from TImpMemberCard
ALTER TABLE
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա
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,
dbo.FNGetFirstPinYin(A.FName),
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 Status !=3
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,
1,
FCompId AS FCompId,
FMemId AS FMemId,
FState AS FState,
FCreateDate AS FCreateDate,
FExpiredDate AS FExpiredDate,
ISNULL(0,0) AS FTotalTimes,
0 AS FUsedTimes,
0 AS FSaleCompId,
0 AS FSaleBillId,
ISNULL(FMemo,'') AS FMemo
FROM TImpMemberCard
WHERE FMemID IN(SELECT FMemId FROM TMember)
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 TImpMemberCard
WHERE FCardId IN(SELECT FCardId FROM TMemberCard)
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,TImpMemberCard AS D
where C.FCardId = A.FCardId
AND C.FCardId = D.FCardId
AND A.FCardId IN(SELECT FCardId FROM TMemberCard)
DELETE TMemberCardAccount WHERE FAcctId = 10
INSERT TMemberCardAccount(FId,FMemId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo)
SELECT dbo.FNNewId(),FMemId,FCardId AS FCardId,10,ISNULL(FBalance2,0),ISNULL(FBalance2,0),0,FCreateDate,NULL,''
FROM TImpMemberCard
WHERE FCardId IN(SELECT FCardId FROM TMemberCard)
AND FBalance2 > 0
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,C.FCardId,10,getdate(),C.FTypeId,C.FCompId,'DR','Import',0,'',ISNULL(D.FBalance2,0),0,ISNULL(D.FBalance2,0),0,getdate(),''
from dbo.TMemberCard AS C,TImpMemberCard AS D
where C.FCardId = D.FCardId
AND D.FCardId IN(SELECT FCardId FROM TMemberCard)
AND FBalance2 > 0