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

416 lines
15 KiB

1 year ago
select * from sysobjects where type = 'U'
SELECT * INTO BASE_KH_JC FROM master..BASE_KH_JC
SELECT * INTO BASE_KH FROM master..BASE_KH
SELECT * INTO BASE_CARD FROM master..BASE_CARD
SELECT * INTO BASE_CARD_JC FROM master..BASE_CARD_JC
SELECT * INTO BASE_CP FROM master..BASE_CP
SELECT * INTO BASE_FW FROM master..BASE_FW
use hz
SELECT * FROM base_kh
SELECT * FROM BASE_CARD
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+10000 ,BM,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 BASE_CARD
UPDATE TMemberCardType SET FAllowRchg = 1 WHERE FId IN(SELECT ID+10000 FROM BASE_CARD)
UPDATE TMemberCardType SET FAllowSale = 1 WHERE FId IN(SELECT ID+10000 FROM BASE_CARD)
UPDATE TMemberCardType SET FEnabled = 1 WHERE FId IN(SELECT ID+10000 FROM BASE_CARD)
UPDATE TMemberCardType SET FValidityPeriod = 100 WHERE FId IN(SELECT ID+10000 FROM BASE_CARD)
UPDATE TMemberCardType SET FValidityPerioduNIT = 1 WHERE FId IN(SELECT ID+10000 FROM BASE_CARD)
UPDATE TMemberCardType SET FExpiredDate = null WHERE FId IN(SELECT ID+10000 FROM BASE_CARD)
UPDATE TMemberCardType SET FDeposit = 0,FDefaultMemo = '' WHERE FId IN(SELECT ID+10000 FROM BASE_CARD)
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 C.FId > 0
AND I.FId IN(SELECT 10000 + ID FROM BASE_CARD)
--<EFBFBD><EFBFBD>Ա
ALTER TABLE BASE_KH ADD FMemId BIGINT
ALTER TABLE BASE_KH ADD FCardId BIGINT
ALTER TABLE BASE_KH ADD FCardTypeName VARCHAR(100)
ALTER TABLE BASE_KH ADD FMemNo VARCHAR(50)
ALTER TABLE BASE_KH ADD FCardNo VARCHAR(50)
ALTER TABLE BASE_KH ADD FName VARCHAR(50)
ALTER TABLE BASE_KH ADD FGender INT
ALTER TABLE BASE_KH ADD FMobile VARCHAR(50)
ALTER TABLE BASE_KH ADD FBirthdayType VARCHAR(50)
ALTER TABLE BASE_KH ADD FBirthday DATETIME
ALTER TABLE BASE_KH ADD FCompId BIGINT
ALTER TABLE BASE_KH ADD FCardTypeId BIGINT
ALTER TABLE BASE_KH ADD FMemo VARCHAR(MAX)
ALTER TABLE BASE_KH ADD FBalance DECIMAL(18,6)
ALTER TABLE BASE_KH ADD FBalance2 DECIMAL(18,6)
ALTER TABLE BASE_KH ADD FPoint DECIMAL(18,6)
ALTER TABLE BASE_KH ADD FCreateDate DATETIME
ALTER TABLE BASE_KH ADD FExpiredDate DATETIME
SELECT * FROM BASE_KH
UPDATE BASE_KH SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL
UPDATE BASE_KH SET FMemId = dbo.FNNewId() WHERE FMemId IS NULL
UPDATE BASE_KH SET FName = name
UPDATE BASE_KH SET FMobile = tel
UPDATE BASE_KH SET FMemNO = CARDNO
UPDATE BASE_KH SET FCardNo = CARDNO
UPDATE BASE_KH SET FCompId = 1
UPDATE BASE_KH SET FGender = CASE WHEN sex = 1001 THEN 1 ELSE 0 END
UPDATE BASE_KH SET FMemo = ISNULL(remark,'')
UPDATE BASE_KH SET FMemo = '' WHERE FMemo IS NULL
UPDATE BASE_KH SET FPoint = KJF
UPDATE BASE_KH SET FBirthdayType = 'G' WHERE BDTYPE = 1002
UPDATE BASE_KH SET FBirthdayType = 'L'WHERE BDTYPE = 1001
UPDATE BASE_KH SET FBirthdayType = 'G'WHERE FBirthdayType IS NULL
UPDATE BASE_KH SET FBirthday=BDAY
UPDATE BASE_KH SET FName = FMobile WHERE FName IS NULL
UPDATE BASE_KH SET FName = FMemNo WHERE FName IS NULL
UPDATE BASE_KH SET FBalance = KYE
UPDATE BASE_KH SET FCreateDate = KKDATE
UPDATE BASE_KH SET FExpiredDate = NULL
UPDATE BASE_KH SET FExpiredDate = DATEADD(YEAR,100,FCreateDate)
UPDATE A
SET A.FCardTypeId = 10000 + B.ID
FROM BASE_KH AS A,BASE_CARD AS B
WHERE A.HYCARD = B.BM
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,
FCreateDate 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,
0 AS FPoint,
1 AS FRecvConsSMS,
1 AS FRecvBulkSMS,
'' AS FMemo,
'' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5
from BASE_KH
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId,
FMemo)
SELECT
FCardId AS FId,
FMemNo AS FNo,
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,
0 AS FTotalTimes,
0 AS FUsedTimes,
FCompId AS FSaleCompId,
0 AS FSaleBillId,
ISNULL(FMemo,'') AS FMemo
FROM BASE_KH
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 BASE_KH
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(),'<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD>'
FROM BASE_KH AS A
SELECT * FROM BASE_KH_JC
use hz
SELECT * FROM BASE_KH WHERE FMemNo = '8880128'
SELECT * FROM TImpMemberCourse
WHERE FItemId IS NULL
UPDATE A
SET A.FItemId = B.FItemId,
A.FCourseId = B.FId
FROM TImpMemberCourse AS A,TItem AS C,TCourse AS B
WHERE B.FItemId = C.FId
AND A.FCourseName = 'С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2'
AND C.FNo = '104'
300<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD>103
200<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD>102
С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD>104
UPDATE A
SET A.FMemId = B.FMemId
FROM TImpMemberCourse AS A,BASE_KH AS B
WHERE A.FMemNO = B.FMemNo
ALTER TABLE TImpMemberCourse ADD FId BIGINT
ALTER TABLE TImpMemberCourse ADD FCompId BIGINT
UPDATE TImpMemberCourse SET FId = dbo.FNNewId()
UPDATE TImpMemberCourse SET FCompId = dbo.FNCompId('001')
SELECT * FROM TCompany
UPDATE TMember SET FCompId = dbo.FNCompId('001') WHERE FMemId IN(SELECT FMemId FROM BASE_KH)
UPDATE TMemberCard SET FCompId = dbo.FNCompId('001') WHERE FMemId IN(SELECT FMemId FROM BASE_KH)
INSERT TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FPurAmount,FFreeTimes,FUsedPurTimes,FFreeAmount,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice)
SELECT FId,FMemId,FCourseId,0,FItemId,FCompId,FRemainTimes,FAdjustPrice * FRemainTimes,0,0,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,'<EFBFBD><EFBFBD><EFBFBD><EFBFBD>',1,ISNULL(FAdjustPrice,0)
FROM TImpMemberCourse
--WHERE FCourseId IS NOT NULL
SELECT * FROM BASE_KH WHERE FMemNo = '8880200'
UPDATE A
SET A.FPoint = B.FPoint
FROM BASE_KH AS B,TMember AS A
WHERE A.FMemId = B.FMemId
UPDATE A
SET A.FCPW = ISNULL(B.CARDPWD,'')
FROM BASE_KH AS B,TMember AS A
WHERE A.FMemId = B.FMemId
INSERT TMemberPointHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransId,FTransNo,FInAmount,FOutAmount,FBalance,FMemo,FRecordTime)
SELECT dbo.FNNewId(),A.FMemId,getdate(),0,1,'DR','Import',0,'',FPoint,0,FPoint,'',getdate()
FROM BASE_KH AS A WHERE FPoint != 0
use hz
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880200'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8880513'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880531'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880529'
UPDATE BASE_KH SET Farrear = 150 WHERE FCardNo = '8880597'
UPDATE BASE_KH SET Farrear = 150 WHERE FCardNo = '8880600'
UPDATE BASE_KH SET Farrear = 100 WHERE FCardNo = '8880560'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8880811'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880087'
UPDATE BASE_KH SET Farrear = 400 WHERE FCardNo = '8880756'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880766'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8880767'
UPDATE BASE_KH SET Farrear = 100 WHERE FCardNo = '8880775'
UPDATE BASE_KH SET Farrear = 500 WHERE FCardNo = '8880700'
UPDATE BASE_KH SET Farrear = 500 WHERE FCardNo = '8880827'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8880172'
UPDATE BASE_KH SET Farrear = 500 WHERE FCardNo = '8880653'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880379'
UPDATE BASE_KH SET Farrear = 150 WHERE FCardNo = '8880839'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8880850'
UPDATE BASE_KH SET Farrear = 100 WHERE FCardNo = '8880851'
UPDATE BASE_KH SET Farrear = 250 WHERE FCardNo = '8880210'
UPDATE BASE_KH SET Farrear = 400 WHERE FCardNo = '8880570'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880185'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880216'
UPDATE BASE_KH SET Farrear = 400 WHERE FCardNo = '8880335'
UPDATE BASE_KH SET Farrear = 150 WHERE FCardNo = '8880059'
UPDATE BASE_KH SET Farrear = 400 WHERE FCardNo = '8880275'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881171'
UPDATE BASE_KH SET Farrear = 500 WHERE FCardNo = '8880501'
UPDATE BASE_KH SET Farrear = 500 WHERE FCardNo = '8881327'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8881317'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880806'
UPDATE BASE_KH SET Farrear = 400 WHERE FCardNo = '8880538'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8880178'
UPDATE BASE_KH SET Farrear = 500 WHERE FCardNo = '8880525'
UPDATE BASE_KH SET Farrear = 400 WHERE FCardNo = '8881072'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8880722'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880051'
UPDATE BASE_KH SET Farrear = 400 WHERE FCardNo = '8880160'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881370'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880832'
UPDATE BASE_KH SET Farrear = 100 WHERE FCardNo = '8880565'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880882'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881619'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881828'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881905'
UPDATE BASE_KH SET Farrear = 400 WHERE FCardNo = '8880581'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881887'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881258'
UPDATE BASE_KH SET Farrear = 400 WHERE FCardNo = '8881553'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881939'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881285'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881609'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880070'
UPDATE BASE_KH SET Farrear = 500 WHERE FCardNo = '8882629'
UPDATE BASE_KH SET Farrear = 400 WHERE FCardNo = '8882622'
UPDATE BASE_KH SET Farrear = 650 WHERE FCardNo = '8882620'
UPDATE BASE_KH SET Farrear = 500 WHERE FCardNo = '8882618'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880399'
UPDATE BASE_KH SET Farrear = 100 WHERE FCardNo = '8882650'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8882738'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880776'
UPDATE BASE_KH SET Farrear = 500 WHERE FCardNo = '8882657'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8882768'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881721'
UPDATE BASE_KH SET Farrear = 100 WHERE FCardNo = '8882003'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881107'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8882070'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880193'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881375'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8882015'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8880518'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881356'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881882'
UPDATE BASE_KH SET Farrear = 100 WHERE FCardNo = '8882058'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8882760'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880770'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8881776'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8882713'
UPDATE BASE_KH SET Farrear = 400 WHERE FCardNo = '8881593'
UPDATE BASE_KH SET Farrear = 400 WHERE FCardNo = '8881987'
UPDATE BASE_KH SET Farrear = 400 WHERE FCardNo = '8881671'
UPDATE BASE_KH SET Farrear = 400 WHERE FCardNo = '8880966'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8882607'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8882098'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881978'
UPDATE BASE_KH SET Farrear = 100 WHERE FCardNo = '8880357'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8881982'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881137'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881756'
UPDATE BASE_KH SET Farrear = 100 WHERE FCardNo = '8882119'
UPDATE BASE_KH SET Farrear = 100 WHERE FCardNo = '8881880'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8880862'
UPDATE BASE_KH SET Farrear = 500 WHERE FCardNo = '8882273'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8880589'
UPDATE BASE_KH SET Farrear = 100 WHERE FCardNo = '8882519'
UPDATE BASE_KH SET Farrear = 800 WHERE FCardNo = '8882261'
UPDATE BASE_KH SET Farrear = 500 WHERE FCardNo = '8882262'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8882516'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881925'
UPDATE BASE_KH SET Farrear = 400 WHERE FCardNo = '8882296'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881995'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8880906'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8881582'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8882081'
UPDATE BASE_KH SET Farrear = 250 WHERE FCardNo = '8881129'
UPDATE BASE_KH SET Farrear = 400 WHERE FCardNo = '8880055'
UPDATE BASE_KH SET Farrear = 200 WHERE FCardNo = '8882026'
UPDATE BASE_KH SET Farrear = 400 WHERE FCardNo = '8882356'
UPDATE BASE_KH SET Farrear = 160 WHERE FCardNo = '8881200'
UPDATE BASE_KH SET Farrear = 300 WHERE FCardNo = '8881262'
UPDATE BASE_KH SET Farrear = 100 WHERE FCardNo = '8882701'
ALTER TABLE BASE_KH ADD FArrear DECIMAL(18,6)
UPDATE BASE_KH SET FArrear = 0 WHERE FArrear IS NULL
UPDATE BASE_KH SET FBalance = kye - FArrear
INSERT TMemberArrear(FId,FMemId,FTime,FCompId,FContentType,FCardId,FBillType,FBizType,FTransId,FTransNo,FTransDetailId,FContentId,FArrear,FEmpId,FRepaid,FAcctArrear)
SELECT dbo.FNNewId(),A.FMemId,getdate(),A.FCompId,'Account',A.FCardId,'DR_KK','DR_CardSale',0,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,0,3,CAST(A.δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> AS FLOAT) ,0,0,0
FROM TImpMemberArrear AS A
WHERE CAST(A.δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> AS FLOAT) > 0
UPDATE A
SET A.FBalance = B.FBalance,A.FArrear= B.FArrear
FROM TMemberCardAcctHist AS A,BASE_KH AS B
WHERE A.FCardId = B.FCardId
SELECT * FROM TCOnsumeBill
SELECT * FROM
TMemberCardAcctHist