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

198 lines
6.2 KiB

ALTER TABLE kxx ADD FCourseId BIGINT
ALTER TABLE kxx ADD FItemId BIGINT
ALTER TABLE kxx ADD FMemId BIGINT
ALTER TABLE kxx ADD FMemNo VARCHAR(50)
ALTER TABLE kxx ADD FCardTypeId BIGINT
ALTER TABLE kxx ADD FName VARCHAR(50)
ALTER TABLE kxx ADD FMobile VARCHAR(50)
ALTER TABLE kxx ADD FMemo VARCHAR(1000)
ALTER TABLE kxx ALTER COLUMN FMemo VARCHAR(8000)
ALTER TABLE kxx ADD FBirthday DATETIME
ALTER TABLE kxx ADD FCreateDate DATETIME
ALTER TABLE kxx ADD FIsCourse BIT
ALTER TABLE kxx ADD FCompId BIGINT
ALTER TABLE kxx ADD FBirhtday DATETIME
ALTER TABLE kxx ADD FPW VARCHAR(50)
ALTER TABLE kxx ADD FGender INT
ALTER TABLE kxx ADD FBriefCode VARCHAR(50)
ALTER TABLE kxx ADD FExpiredDate VARCHAR(100)
ALTER TABLE kxx ADD FBalance DECIMAL(18,6)
ALTER TABLE kxx ADD FRemainTimes DECIMAL(18,6)
ALTER TABLE kxx ADD FCardId BIGINT
ALTER TABLE kxx ADD FCardState INT
ALTER TABLE kxx ADD FCalcMode INT
ALTER TABLE kxx ADD FValueType INT
ALTER TABLE kxx ADD FState INT
ALTER TABLE kxx ADD FDeleted BIT
SELECT * FROM Kxx
UPDATE kxx SET FDeleted = 1 WHERE zt = '回收'
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(),'' + ,,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 kxx
GROUP BY
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 NOT EXISTS(SELECT TOP 1 1 FROM TMemberCardTypeSub AS B WHERE B.FCompId = C.FId AND B.FCardTypeId = I.FId)
UPDATE kxx SET FMemId = dbo.FNNewId() WHERE FMemId IS NULL
UPDATE kxx SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL
UPDATE kxx SET FMemNO = kh
UPDATE kxx SET FName = xm
UPDATE kxx SET FGender = CASE WHEN xb = '' THEN 1 ELSE 0 END
UPDATE kxx SET FBalance = je
UPDATE kxx SET FMobile = Tel
UPDATE kxx SET FCreateDate =
UPDATE kxx SET FExpiredDate = sxrq
UPDATE kxx SET FCompiD = 1
UPDATE kxx SET FMemo = WHERE != ''
UPDATE kxx SET FState = 1
UPDATE A
SET A.FCardTypeId = B.FId,
A.FValueType = B.FValueType
FROM kxx AS A,TMemberCardType AS B
WHERE A. = B.FName
--插入会员
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(FBriefCode),
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 kxx
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,
FValueType,
FCompId AS FCompId,
FMemId AS FMemId,
FState 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 KXX
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 KXX
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,KXX AS D
where C.FCardId = A.FCardId
AND C.FCardId = D.FCardId
DELETE TMemberCardAccount WHERE FCardId IN(SELECT FCardId FROM kxx WHERE FDeleted = 1)
DELETE TMemberCardAcctHist WHERE FCardId IN(SELECT FCardId FROM kxx WHERE FDeleted = 1)
DELETE TMemberCard WHERE FCardId IN(SELECT FCardId FROM kxx WHERE FDeleted = 1)
DELETE TMember WHERE FMemId IN(SELECT FMemId FROM kxx WHERE FDeleted = 1)
select * from dbo.xfk WITH(NOLOCK)
ALTER TABLE xfk ADD FMemId BIGINT
ALTER TABLE xfk ADD FCompId BIGINT
ALTER TABLE xfk ADD FCardId BIGINT
ALTER TABLE xfk ADD FId BIGINT
UPDATE A
SET A.FCompId = B.FCompId,
A.FMemId = B.FMemId,
A.FCardId = B.FCardId,
A.FId= dbo.FNnewId()
FROM kxx AS B,xfk AS A
WHERE A.kh = B.kh
INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo)
SELECT FId,A.FMemId,date,A.FCardId,A.FCompId,'DR','Import','','',cast(xfje as decimal(18,6)),1,cast(xfje as decimal(18,6)),'','',bz
FROM xfk AS A