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

236 lines
7.7 KiB

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(),¿¨Ãû³Æ AS FNo,¿¨Ãû³Æ,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 ¿¨Ãû³Æ
ORDER 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 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 = »áÔ±ÐÕÃû
UPDATE TImpMember SET FMobile = »áÔ±ÊÖ»ú
UPDATE TImpMember SET FMemNo = ¿¨ºÅ
UPDATE TImpMember SET FCardNO = ¿¨ºÅ
UPDATE TImpMember SET FBalance = [¿¨Óàî(Ôª)]
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.¿¨Ãû³Æ = B.FName
SELECT * FROM TImpMember2
UPDATE TImpMember2 SET »áÔ±¿¨ºÅ = replace(»áÔ±¿¨ºÅ,'¡¡','')
UPDATE TImpMember2 SET »áÔ±¿¨ºÅ = replace(»áÔ±¿¨ºÅ,' ','')
UPDATE TImpMember2 SET »áÔ±¿¨ºÅ = replace(»áÔ±¿¨ºÅ,' ','')
UPDATE TImpMember2 SET ¿ª¿¨Ê±¼ä = replace(¿ª¿¨Ê±¼ä,' ','')
UPDATE TImpMember2 SET ¿ª¿¨Ê±¼ä = replace(¿ª¿¨Ê±¼ä,' ','')
UPDATE TImpMember2 SET ¿ª¿¨Ê±¼ä = replace(¿ª¿¨Ê±¼ä,'"','')
UPDATE TImpMember2 SET ¿ª¿¨Ê±¼ä = LEFT(¿ª¿¨Ê±¼ä,10 ) + ' ' + RIGHT(¿ª¿¨Ê±¼ä,8)
SELECT * FROM TIMpMember2
UPDATE TIMpMember SET FGender = 0
UPDATE A
SET A.FGender =1
FROM TIMpMember AS A,TIMpMember2 AS B
WHERE A.¿¨ºÅ = B.»áÔ±¿¨ºÅ
AND ISNULL(B.»áÔ±ÐÔ±ð,'') = 'ÄÐ'
UPDATE A
SET A.FMemo = ISNULL(»áÔ±±¸×¢,''),
A.FCreateDate = ISNULL(¿ª¿¨Ê±¼ä,getdate())
FROM TIMpMember AS A,TIMpMember2 AS B
WHERE A.¿¨ºÅ = B.»áÔ±¿¨ºÅ
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
--²åÈë»áÔ±
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 ¿¨ºÅ = '' AND ½»Ò×Á÷Ë®ºÅ 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.¿¨ºÅ = B.¿¨ºÅ
INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo)
SELECT DBO.FNNewId(),A.FMemId,A.½»Ò×ʱ¼ä,0,A.FCompId,'DR','Import',½»Ò×Á÷Ë®ºÅ,½»Ò×ÀàÐÍ,CAST([ÊÕÈë(ʵ¼ÊÊÕÈë)] AS FLOAT) + CAST([Ö§³ö(ʵ¼ÊÖ§³ö)] AS FLOAT),
1,CAST([ÊÕÈë(ʵ¼ÊÊÕÈë)] AS FLOAT) + CAST([Ö§³ö(ʵ¼ÊÖ§³ö)] AS FLOAT),'','',''
FROM TImpMemberTransHist AS A
WHERE ISNULL(FMemId,0) != 0