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

367 lines
12 KiB

1 year ago
SELECT * FROM TImp
SELECT * FROM imp_member_card
SELECT * FROM imp_card_type
--
SELECT * FROM imp_card_type
ALTER TABLE imp_card_type ADD FCardTypeId BIGINT
ALTER TABLE imp_card_type ADD FCardTypeNo VARCHAR(50)
ALTER TABLE imp_card_type ADD FCardTypeName VARCHAR(50)
UPDATE imp_card_type
SET FCardTypeId = CardCategoryId,
FCardTypeName = CardCategoryName,
FCardTypeNo = HotKey
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 =FCardTypeId, FCardTypeNo,FCardTypeName,1,FMaterial = 2,Price,FCardFeeAmt = 0,FAcctId = 3,FDeposit = StoredValue,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 imp_card_type
INSERT INTO TMemberCardTypeSub(FId,FCompId,FCardTypeId,FAllowSale,FAllowRchg,FEnabled)
SELECT dbo.FNNewId(),dbo.FNCompId('001'),I.FCardTypeId,1,1,1
FROM imp_card_type AS I
SELECT * FROM imp_member AS A,imp_member_card AS B
WHERE A.FNo = B.FCLientNO
AND A.FName = ''
AND FMoney > 0
SELECT * FROM imp_member
SELECT * FROM imp_member_card
SELECT * FROM imp_member_card WHERE FClientNO = '0003'
ALTER TABLE imp_member_card ADD FCardTypeName VARCHAR(100)
ALTER TABLE imp_member_card ADD FMemId BIGINT
ALTER TABLE imp_member_card ADD FCardNo VARCHAR(50)
ALTER TABLE imp_member_card ADD FCardState INT
ALTER TABLE imp_member_card ADD FCardTypeId BIGINT
ALTER TABLE imp_member_card ADD FBalance DECIMAL(18,6)
ALTER TABLE imp_member_card ADD FBalance2 DECIMAL(18,6)
ALTER TABLE imp_member_card ADD FRemainTimes INT
ALTER TABLE imp_member_card ADD FCreateDate DATETIME
ALTER TABLE imp_member_card ADD FExpiredDate DATETIME
ALTER TABLE imp_member_card ADD FMemo VARCHAR(1000)
ALTER TABLE imp_member_card ADD FCompId BIGINT
ALTER TABLE imp_member_card ADD FCardId BIGINT
ALTER TABLE imp_member ADD FCompId BIGINT
ALTER TABLE imp_member ADD FMemId BIGINT
ALTER TABLE imp_member ADD FMemNo VARCHAR(50)
ALTER TABLE imp_member ADD FName VARCHAR(50)
ALTER TABLE imp_member ADD FGender INT
ALTER TABLE imp_member ADD FMobile VARCHAR(50)
ALTER TABLE imp_member ADD FMemo VARCHAR(1000)
ALTER TABLE imp_member ADD FArrear DECIMAL(18,6)
ALTER TABLE imp_member ADD FPoint DECIMAL(18,6)
ALTER TABLE imp_member ADD FState INT
ALTER TABLE imp_member ADD FCreateDate DATETIME
ALTER TABLE imp_member ADD FDeleted BIT
ALTER TABLE imp_member ADD FBirthday DATETIME
ALTER TABLE imp_member ADD FBirthdayType CHAR
--ID
UPDATE imp_member SET FMemId=MemberShopId
--ID
UPDATE imp_member_card SET FCardId=MCID
SELECT * FROM imp_member_card
--ID
UPDATE A
SET A.FMemId = B.FMemId
FROM imp_member AS B,imp_member_card AS A
WHERE A.MemberShopId = B.MemberShopId
--,,,,
UPDATE imp_member SET FName = TrueName,FMobile = Mobile,FGender = Sex ,
FBirthdayType = CASE WHEN BirthdayType = 2 THEN 'G' ELSE 'L' END,
FBirthday = REPLACE(BirthdayText,' (农历)',''),
FCreateDate = CreateTime,
FPoint = WebPoints
SELECT BirthdayText FROM imp_member
WHERE BirthdayText != ''
UPDATE imp_member SET FBirthday = NULL WHERE FBirthday = '1900-01-01 00:00:00.000'
--
UPDATE imp_member SET FCompId = 1
--
--select * from imp_member_card
UPDATE imp_member_card SET FCardNo = MemberCardId
--
UPDATE imp_member SET FMemNo = ''
UPDATE A
SET A.FMemNo = B.FCardNo
FROM imp_member AS A,imp_member_card AS B
WHERE A.FMemId = B.FMemId
UPDATE imp_member SET FMemNO = FMobile WHERE ISNULL(FMemNo,'') = ''
--,
UPDATE imp_member SET FDeleted = 0
UPDATE imp_member SET FDeleted = 1
WHERE MemberShopId NOT IN(SELECT MemberShopId FROM imp_member_card)
-- AND MemberShopId NOT IN(SELECT MemberShopId FROM imp_member_course)
AND FMemNo IN(
SELECT FMemNo
FROM imp_member
WHERE FDeleted = 0
GROUP BY FMemNo
HAVING(SUM(1) > 1)
)
--
UPDATE A
SET A.FCardTypeID = B.FId
FROM imp_member_card AS A,TMemberCardType AS B
WHERE A.MemberCardCategoryName = B.FName
SELECT * FROM imp_member_card WHERE FCardTypeId IS NULL
select * from imp_member WHERE MemberShopId = 51071442
--
UPDATE imp_member_card SET FCardState = 1 WHERE CardStatusStr = '正常'
UPDATE imp_member_card SET FCardState = 1 WHERE CardStatusStr = '过期'
UPDATE imp_member_card SET FCardState = 4 WHERE CardStatusStr = '冻结'
SELECT *FROM imp_member_card WHERE CardStatusStr != '正常'
SELECT * FROM imp_member_card WHERE FCardState =
--
UPDATE imp_member_card SET FBalance =NowAmount,FBalance2 = NowGiveAmount
--
UPDATE imp_member_card SET FCreateDate = CreateTimeStr
UPDATE imp_member_card SET FExpiredDate = ExpiredDateStr WHERE ExpiredDateStr != '无限期'
UPDATE imp_member_card SET FExpiredDate = '9000-01-01' WHERE ExpiredDateStr = '无限期'
UPDATE imp_member_card SET FCompId = 1
--ID
SELECT * FROM imp_member_course
UPDATE imp_member_course SET FCardId = MCID
UPDATE imp_member_course SET FMemId = MemberId
UPDATE imp_member_course SET FCompId= 1
UPDATE imp_member_course SET FState = 1 WHERE CardStatusStr = '正常'
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,
FPoint AS FPoint,
1 AS FRecvConsSMS,
1 AS FRecvBulkSMS,
'' AS FMemo,
'从老系统导入' AS FCustom1,ShopName AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5
from imp_member
WHERE FDeleted = 0
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId,
FMemo)
SELECT
FCardId AS FId,
FCardNo AS FNo,
FCardTypeId AS FTypeId,
(SELECT FValueType FROM TMemberCardType WHERE FId = FCardTypeId) AS FValueType,
FCompId AS FCompId,
FMemId AS FMemId,
FCardState 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 imp_member_card
WHERE FMemId IN(SELECT FMemId FROM TMember)
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 imp_member_card AS A
WHERE FMemId IN(SELECT FMemId FROM TMember)
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(),'从星沙龙中导入'
FROM imp_member_card AS A
WHERE FMemId IN(SELECT FMemId FROM TMember)
INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo)
SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,10,FBalance2,FBalance2,0,FCreateDate,NULL AS FExpiredDate,''
FROM imp_member_card AS A
WHERE FBalance2 != 0
AND FMemId IN(SELECT FMemId FROM TMember)
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,10,getdate(),A.FCardTypeId,A.FCompId,'DR','Import',0,'',A.FBalance2,0,A.FBalance2,0,getdate(),'从星沙龙中导入'
FROM imp_member_card AS A
WHERE FBalance2 != 0
AND FMemId IN(SELECT FMemId FROM TMember)
--
SELECT * FROM imp_member_course
SELECT * FROM TImpMemberCourseDetail
ALTER TABLE imp_member_course ADD FMemId BIGINT
ALTER TABLE TIMpMemberCourseDetail ADD FPurTimes INT
ALTER TABLE TIMpMemberCourseDetail ADD FUsedPurTimes INT
ALTER TABLE TIMpMemberCourseDetail ADD FPurAmount DECIMAL(18,6)
ALTER TABLE TIMpMemberCourseDetail ADD FItemId BIGINT
ALTER TABLE TIMpMemberCourseDetail ADD FCourseId BIGINT
ALTER TABLE TIMpMemberCourseDetail ADD FCreateDate DATETIME
ALTER TABLE TIMpMemberCourseDetail ADD FExpiredDate DATETIME
ALTER TABLE TIMpMemberCourseDetail ADD FCompId BIGINT
ALTER TABLE TIMpMemberCourseDetail ADD FMemId BIGINT
ALTER TABLE TIMpMemberCourseDetail ADD FCardId BIGINT
UPDATE imp_member_course SET FMemId = MemberId
UPDATE A
SET A.FMemId = B.FMemId
FROM TImpMemberCourseDetail AS A,imp_member_course AS B
WHERE A.MCID = B.MCID
UPDATE TImpMemberCourseDetail SET FCardId = MCID
UPDATE TImpMemberCourseDetail SET FCompId = 1
UPDATE TImpMemberCourseDetail SET FCourseId = 4854799989982317296
UPDATE TImpMemberCourseDetail SET FItemid = 5364344419216701040
UPDATE TImpMemberCourseDetail SET FCreateDate = CreateTimeStr
UPDATE TImpMemberCourseDetail SET FExpiredDate = ExpiredDateStr
INSERT TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FUsedPurTimes,FPurAmount,FFreeTimes,FFreeAmount,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice)
SELECT FCardId,FMemId,FCourseId,0,FItemId,FCompId,ConsumeTimes + 0 + Times + 0,ConsumeTimes,0,0,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,'新沙龙导入',1,0
FROM TImpMemberCourseDetail AS A
INSERT INTO TMemberCourseLog(FId,FMemId,FCardId,FPackId,FCourseId,FTime,FInPurTimes,FInFreeTimes,FOutPurTimes,FOutFreeTimes,FCompId,FBillType,FBizType,FBillId,FBillNo,FBillDetailId,FRecordTime)
SELECT dbo.FNNewId(),FMemId,A.FCardId AS FCardId,0, ISNULL(FCourseId,0),getdate(),ConsumeTimes + 0 + Times + 0,0,ConsumeTimes,0,FCompId,'DR','Import',0,'',0,getdate()
FROM TImpMemberCourseDetail AS A
DELETE TMemberCourseLog WHERE FCardId IN(SELECT FCardId FROM TImpMemberCourseDetail)
DELETE TMemberCourse WHERE FId IN(SELECT FCardId FROM TImpMemberCourseDetail)
SELECT * FROM TCourse
DROP TABLE imp_member_course
ALTER TABLE imp_Member_trans_hist_detail ADD
--
ALTER TABLE imp_member_trans_hist ADD FCompId BIGINT
UPDATE imp_member_trans_hist SET FCompID = 1
INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo)
SELECT dbo.FNNewId(),A.MemberId,A.CreateTimeStr,0,A.FCompId,'DR','Import',ConsumeBillNo,ContentStr,0,1,0,Payments,EmployeeNames,''
FROM imp_member_trans_hist AS A ,imp_Member_trans_hist_detail AS B
WHERE A.Id = B.Id
AND A.MemberId IN(SELECT FMemId FROM TMember)
SELECT * FROM imp_member_trans_hist where id = 4911593833057529541
SELECT * FROM imp_Member_trans_hist_detail
DROP TABLE imp_member_trans_hist
DROP TABLE imp_Member_trans_hist_detail
SELECT Id FROM imp_Member_trans_hist_detail GROUP BY ID HAVING(SUM(1) > 1)
SELECT * FROM TMember WHERE FMemId=
3709596
1006684
/**
13854209915,123456
18669871559", 123456
15726228884 ssf12345678
*/