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

216 lines
5.9 KiB

1 year ago
sp_rename 'MEMHIS1','TImpMemberLocal'
sp_rename 'TImpMemberLocal','TImpMemberLocal_1'
SELECT * FROM TImpMember
WHERE FMemNo IN(SELECT FMemNO FROM TMember)
WHERE FMemNo = 'WA50805630'
DELETE TMemberCardAcctHist
DELETE TMemberCardAccount
DELETE TMemberCard WHERE FCardid > 0
DELETE TMember WHERE FMemId > 0
SELECT * FROM TImpMember WHERE <EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IS NULL
DELETE TImpMember WHERE <EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> IS NULL
DELETE TImpMember_Normal WHERE <EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> IS NULL
DELETE TImpMember_Loss WHERE <EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> IS NULL
DELETE TImpMember_Invalid WHERE <EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD> IS NULL
ALTER TABLE TImpMember ADD FMemId BIGINT
ALTER TABLE TImpMember ADD FCardNo VARCHAR(50)
ALTER TABLE TImpMember ADD FMemNo VARCHAR(50)
ALTER TABLE TImpMember ADD FName VARCHAR(50)
ALTER TABLE TImpMember ADD FGender INT
ALTER TABLE TImpMember ADD FMobile VARCHAR(50)
ALTER TABLE TImpMember ADD FTelephone VARCHAR(50)
ALTER TABLE TImpMember ADD FCardTypeId BIGINT
ALTER TABLE TImpMember ADD FCourseId BIGINT
ALTER TABLE TImpMember ADD FBalance DECIMAL(18,6)
ALTER TABLE TImpMember ADD FRemainTimes INT
ALTER TABLE TImpMember ADD FPurTimes INT
ALTER TABLE TImpMember ADD FPurAmount DECIMAL(18,6)
ALTER TABLE TImpMember ADD FItemId BIGINT
ALTER TABLE TImpMember ADD FCreateDate DATETIME
ALTER TABLE TImpMember ADD FExpiredDate DATETIME
ALTER TABLE TImpMember ADD FCompId BIGINT
ALTER TABLE TImpMember ADD FCardId BIGINT
ALTER TABLE TImpMember ADD FMemo VARCHAR(1000)
ALTER TABLE TImpMember ADD FArrear DECIMAL(18,6)
ALTER TABLE TImpMember ADD FPoint DECIMAL(18,6)
ALTER TABLE TImpMember ADD FBirthday DATETIME
ALTER TABLE TImpMember ADD FBirthdayType CHAR
ALTER TABLE TImpMember ADD FDeleted BIT
ALTER TABLE TImpMember ADD FCardState INT
UPDATE TImpMember SET FMemId = dbo.FNNewId() WHERE FMemid IS NULL
UPDATE TImpMember SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL
UPDATE TImpMember SET FCardNo = SUBSTRING(<EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,2,LEN(<EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>))
UPDATE TImpMember SET FMemNo = FCardNo
UPDATE TImpMember SET FName = ISNULL(<EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,FMemNo)
UPDATE TImpMember SET FMobile = ISNULL(CAST(CAST(<EFBFBD>ͻ<EFBFBD><EFBFBD>ֻ<EFBFBD> AS BIGINT ) AS VARCHAR) ,'')
UPDATE TImpMember SET FCompId = dbo.FNCompId('003')
UPDATE TImpMember SET FBalance = <EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
--<EFBFBD>Ա<EFBFBD>
UPDATE A
SET A.FGender = CASE WHEN B.SEX = 2 THEN 1 ELSE 0 END
FROM TImpMember AS A,TImpMemberLocal AS B
WHERE A.FMemNO = B.MNO
UPDATE TImpMember SET FGender = 0 WHERE FGender iS NULL
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/*UPDATE A
SET A.FCardTypeId = B.FId
FROM TImpMember AS A,TMemberCardType AS B
WHERE CAST(A.MVCode AS VARCHAR) = B.FNo
*/
UPDATE A
SET A.FCardTypeId = B.FId
FROM TImpMember AS A,TMemberCardType AS B
WHERE B.FNo = '3'
SELECT * FROM TMemberCardType
--<EFBFBD><EFBFBD>ע
UPDATE A
SET A.FMemo = B.ADDR + ' ' + B.REM1
FROM TImpMember AS A,TImpMemberLocal AS B
WHERE A.FMemNO = B.MNO
UPDATE TImpMember SET FMemo = '' WHERE FMemNo IS NULL
UPDATE A
SET A.FCreateDate= LEFT(BDate,4) + '-' + SUBSTRING(BDate,5,2)+ '-' + RIGHT(BDate,2)
FROM TImpMemberLocal AS B,TImpMember AS A
WHERE LEN(BDate ) = 8
select BDate FROM TImpMemberLocal WHERE LEN(BDate ) != 8
UPDATE TImpMember SET FCreateDate = getdate()
UPDATE TImpMember SET FExpiredDate = dateadd(year,100,getdate())
UPDATE a
SET A.FBirthday = B.BIRTHDAY
FROM TImpMember AS A,TImpMemberLocal AS B
WHERE LEN(BIRTHDAY) = 8
AND A.FMemNo = B.MNO
UPDATE A
SET A.FDeleted = 0,
A.FCardState = 1
FROM TImpMember AS A
--<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 AS FMemId,
FMemNo AS FMemNo,
FName AS FName,
dbo.FNGetFirstPinYin(FName),
0 AS FTypeId,
FCompId AS FCompId,
ISNULL(FCreateDate ,'1900-01-01') AS FCreateDate,
FGender AS FGender,
'G' 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,
ISNULL( FPoint,0) AS FPoint,
1 AS FRecvConsSMS,
1 AS FRecvBulkSMS,
ISNULL('','') AS FMemo,
'' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5
from TImpMember
WHERE FDeleted = 0
INSERT INTO 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 AS FTypeId,
(SELECT FValueType FROM TMemberCardType WHERE FId = FCardTypeId) AS FValueType,
FCompId AS FCompId,
FMemId AS FMemId,
FCardState AS FState,
ISNULL(FCreateDate,1900) AS FCreateDate,
FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FCompId AS FSaleCompId,
0 AS FSaleBillId,
ISNULL(FMemo,'') AS FMemo
FROM TImpMember
WHERE FDeleted = 0
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,''
FROM TImpMember AS A
WHERE FDeleted = 0
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 TImpMember AS A
WHERE FDeleted = 0