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

237 lines
7.7 KiB

1 year ago
use chongqing_kadiya1
ALTER TABLE TImpMember ADD FCourseId BIGINT
ALTER TABLE TImpMember ADD FItemId BIGINT
ALTER TABLE TImpMember ADD FMemId BIGINT
ALTER TABLE TImpMember ADD FMemNo VARCHAR(50)
ALTER TABLE TImpMember ADD FCardnO VARCHAR(50)
ALTER TABLE TImpMember ADD FCardTypeId BIGINT
ALTER TABLE TImpMember ADD FName VARCHAR(50)
ALTER TABLE TImpMember ADD FMobile VARCHAR(50)
ALTER TABLE TImpMember ADD FMemo VARCHAR(1000)
ALTER TABLE TImpMember ALTER COLUMN FMemo VARCHAR(8000)
ALTER TABLE TImpMember ADD FBirthday DATETIME
ALTER TABLE TImpMember ADD FCreateDate DATETIME
ALTER TABLE TImpMember ADD FIsCourse BIT
ALTER TABLE TImpMember ADD FCompId BIGINT
ALTER TABLE TImpMember ADD FBirhtday DATETIME
ALTER TABLE TImpMember ADD FPW VARCHAR(50)
ALTER TABLE TImpMember ADD FGender INT
ALTER TABLE TImpMember ADD FBriefCode VARCHAR(50)
ALTER TABLE TImpMember ADD FExpiredDate VARCHAR(100)
ALTER TABLE TImpMember ADD FBalance DECIMAL(18,6)
ALTER TABLE TImpMember ADD FRemainTimes DECIMAL(18,6)
ALTER TABLE TImpMember ADD FCardId BIGINT
ALTER TABLE TImpMember ADD FCardState INT
ALTER TABLE TImpMember ADD FCalcMode INT
ALTER TABLE TImpMember ADD FValueType 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> AS FNo,<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 TImpMember
GROUP BY <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ORDER BY <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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 = dbo.FNCompId('001')
AND NOT EXISTS(SELECT TOP 1 1 FROM TMemberCardTypeSub AS B WHERE B.FCompId = C.FId AND B.FCardTypeId = I.FId)
SELECT * FROM TImpMember
UPDATE TImpMember SET FMemId = dbo.FNNewId() WHERE FMemId IS NULL
UPDATE TImpMember SET FName = <EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE TImpMember SET FMobile = <EFBFBD><EFBFBD>Ա<EFBFBD>ֻ<EFBFBD>
UPDATE TImpMember SET FMemNo = <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE TImpMember SET FCardNO = <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE TImpMember SET FBalance = [<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(Ԫ)]
UPDATE TImpMember SET FCompId = dbo.FNCompId('001')
UPDATE TImpMember SET FCreateDate = GETDATE()
UPDATE TImpMember SET FExpiredDate = '9000-01-01'
UPDATE TImpMember SET FBirthday = NULL
UPDATE TImpMember SET FGender = 0
UPDATE TImpMember SET FCardState = 1
UPDATE TImpMember SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL
UPDATE A
SET A.FCardTypeId = B.FId
FROM TImpMember AS A,TMemberCardType AS B
WHERE A.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> = B.FName
SELECT * FROM TImpMember2
UPDATE TImpMember2 SET <EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> = replace(<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,'<EFBFBD><EFBFBD>','')
UPDATE TImpMember2 SET <EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> = replace(<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,' ','')
UPDATE TImpMember2 SET <EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> = replace(<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,' ','')
UPDATE TImpMember2 SET <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD> = replace(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>,' ','')
UPDATE TImpMember2 SET <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD> = replace(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>,' ','')
UPDATE TImpMember2 SET <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD> = replace(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>,'"','')
UPDATE TImpMember2 SET <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD> = LEFT(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>,10 ) + ' ' + RIGHT(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>,8)
SELECT * FROM TIMpMember2
UPDATE TIMpMember SET FGender = 0
UPDATE A
SET A.FGender =1
FROM TIMpMember AS A,TIMpMember2 AS B
WHERE A.<EFBFBD><EFBFBD><EFBFBD><EFBFBD> = B.<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
AND ISNULL(B.<EFBFBD><EFBFBD>Ա<EFBFBD>Ա<EFBFBD>,'') = '<EFBFBD><EFBFBD>'
UPDATE A
SET A.FMemo = ISNULL(<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>ע,''),
A.FCreateDate = ISNULL(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>,getdate())
FROM TIMpMember AS A,TIMpMember2 AS B
WHERE A.<EFBFBD><EFBFBD><EFBFBD><EFBFBD> = B.<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FCreateDate = B.FCreateDate,
A.FGender = B.FGender
FROM TMember AS A,TImpMember AS B
WHERE A.FMemId = B.FMemId
UPDATE A
SET A.FCreateDate = B.FCreateDate,
A.FMemo = B.FMemo
FROM TMemberCard AS A,TImpMember AS B
WHERE A.FMemId = B.FMemId
--<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 FMemId,
FMemNo,
FName,
dbo.FNGetFirstPinYin(FName),
0 AS FTypeId,
FCompId,
FCreateDate,
FGender,
'G' AS FBirthdayType,
FBirthday,
'' AS FTelephone,
FMobile ,
'' AS FQQ,
'' AS FWeChat,
'' AS FIdCard,
'' AS FEmail,
'' AS FAddress,
0 AS FProId,
ISNULL(FPW,'') AS FCPW,
ISNULL(FPW,'') AS FQPW,
0 AS FChargeEmpId,
0 AS FPoint,
1 AS FRecvConsSMS,
1 AS FRecvBulkSMS,
'',
'' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5
from TImpMember
--
INSERT INTO dbo.TMemberCard(
FCardId,
FCardNo,
FCardFaceNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId,
FMemo)
SELECT
FCardId AS FId,
FMemNo AS FNo,
FMemNo AS FFaceNo,
FCardTypeId,
1 AS FValueType,
FCompId AS FCompId,
FMemId AS FMemId,
FCardState AS FState,
FCreateDate AS FCreateDate,
FExpiredDate AS FExpiredDate,
ISNULL(FRemainTimes,0) AS FTotalTimes,
0 AS FUsedTimes,
0 AS FSaleCompId,
0 AS FSaleBillId,
ISNULL(FMemo,'') AS FMemo
FROM TImpMember
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 TImpMember
WHERE FCalcMode != 1
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,TImpMember AS D
where C.FCardId = A.FCardId
AND C.FCardId = D.FCardId
SELECT * FROM TImpMemberTransHist
DELETE TImpMemberTransHist WHERE <EFBFBD><EFBFBD><EFBFBD><EFBFBD> = '' AND <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˮ<EFBFBD><EFBFBD> IS NULL
DELETE TMemberOldTransHist
ALTER TABLE TImpMemberTransHist ADD FMemId BIGINT
ALTER TABLE TImpMemberTransHist ADD FCardId BIGINT
ALTER TABLE TImpMemberTransHist ADD FCompId BIGINT
UPDATE TImpMemberTransHist SET FCompId = dbo.FNCompId('001')
UPDATE A
SET A.FMemId = B.FMemId,
A.FCardId = B.FCardId
FROM TImpMemberTransHist AS A,TImpMember AS B
WHERE A.<EFBFBD><EFBFBD><EFBFBD><EFBFBD> = B.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo)
SELECT DBO.FNNewId(),A.FMemId,A.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>,0,A.FCompId,'DR','Import',<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˮ<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,CAST([<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)] AS FLOAT) + CAST([֧<EFBFBD><EFBFBD>(ʵ<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>)] AS FLOAT),
1,CAST([<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)] AS FLOAT) + CAST([֧<EFBFBD><EFBFBD>(ʵ<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>)] AS FLOAT),'','',''
FROM TImpMemberTransHist AS A
WHERE ISNULL(FMemId,0) != 0