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

603 lines
18 KiB

use KunMing_DingSi
use lijiang_weimeisisong
SELECT * FROM imp_member WHERE FMobile = '13097447666'
SELECT * FROM imp_member_1 WHERE FMobile = '13097447666'
SELECT count(1) FROM imp_member_card
SELECT * FROM imp_member_card_1 WHERE ='13097447666'
delete imp_member
--删除多导入的重复的
SELECT ,SUM(1)
FROM imp_member
GROUP BY
HAVING SUM(1) > 1
SELECT COUNT(1) FROM imp_member WHERE = 6161
ALTER TABLE imp_member ADD FIndex INT IDENTITY(1,1)
SELECT * FROM imp_member
SELECT SUM(CAST( AS FLOAT))
FROM imp_member
select count(1) from imp_member WHERE isnull (,'') =''
DELETE A
FROM imp_member AS A,(
SELECT ,,,,,,,,,,MAX(FIndex) AS FIndex
FROM imp_member
GROUP BY ,,,,,,,,,) AS B
WHERE A. = B.
AND A. = B.
AND A. = B.
AND A. = B.
AND A. = B.
AND A. = B.
AND A. = B.
AND A. = B.
AND A. = B.
AND A. = B.
AND A.FIndex != B.FIndex
--添加没有的
insert imp_member_card(,,)
SELECT ,, FROM imp_member WHERE ISNULL(,'') = ''
AND NOT IN(SELECT FROM imp_member_card)
ALTER TABLE imp_member_card ADD FCardKind VARCHAR(100)
UPDATE imp_member_card SET FCardKind = 'Money'
WHERE ( NOT LIKE '%天%' AND NOT LIKE '%次%' AND LIKE '%元%')
OR ( NOT LIKE '%天%' AND NOT LIKE '%次%' AND NOT LIKE '%元%')
UPDATE imp_member_card SET FCardKind = 'Course' WHERE FCardKind IS NULL
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(), FCardTypeName,FCardTypeName,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 (
SELECT AS FCardTypeName FROM imp_member_card
WHERE FCardKind = 'Money'
) AS A
WHERE FCardTypeName NOT IN(SELECT FNo FROM TMemberCardType)
GROUP BY FCardTypeName
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 != 0
-- AND C.FNo = '009'
AND NOT EXISTS(SELECT TOP 1 1 FROM TMemberCardTypeSub AS B WHERE B.FCompId = C.FId AND B.FCardTypeId = I.FId)
INSERT INTO TMemberCardTypeSub(FId,FCompId,FCardTypeId,FAllowSale,FAllowRchg,FEnabled)
SELECT FId,dbo.FNCompId('001'),I.FId,1,1,1
FROM TMemberCardType AS I
WHERE FId NOT IN(SELECT FCardTypeId FROM TMemberCardTypeSub)
ALTER TABLE imp_member ADD FCardTypeName VARCHAR(100)
ALTER TABLE imp_member ADD FMemId BIGINT
ALTER TABLE imp_member ADD FMemNo VARCHAR(50)
ALTER TABLE imp_member ADD FCardNo VARCHAR(50)
ALTER TABLE imp_member ADD FName VARCHAR(50)
ALTER TABLE imp_member ADD FGender INT
ALTER TABLE imp_member ADD FCardState INT
ALTER TABLE imp_member ADD FMobile VARCHAR(50)
ALTER TABLE imp_member ADD FCardTypeId BIGINT
ALTER TABLE imp_member ADD FCourseId BIGINT
ALTER TABLE imp_member ADD FBalance DECIMAL(18,6)
ALTER TABLE imp_member ADD FBalance2 DECIMAL(18,6)
ALTER TABLE imp_member ADD FRemainTimes INT
ALTER TABLE imp_member ADD FPurTimes INT
ALTER TABLE imp_member ADD FPurAmount DECIMAL(18,6)
ALTER TABLE imp_member ADD FItemId BIGINT
ALTER TABLE imp_member ADD FCreateDate DATETIME
ALTER TABLE imp_member ADD FExpiredDate DATETIME
ALTER TABLE imp_member ADD FCompId BIGINT
ALTER TABLE imp_member ADD FCardId BIGINT
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 FDeleted BIT
ALTER TABLE imp_member ADD FBirthday DATETIME
ALTER TABLE imp_member ADD FBirthdayType CHAR
UPDATE imp_member_card SET FCompId = 1
SELECT * FROM TCompany
UPDATE A
SET A.FCompId = B.FId
FROM imp_member AS A,TCompany AS B
WHERE A. = B.FWebsite
SELECT * FROM imp_member WHERE FCompId IS NULL
UPDATE imp_member_card SET FCompId = 1
SELECT * FROM TCompany
UPDATE imp_member SET FMemId = dbo.FNNewId() WHERE FMemId IS NULL
UPDATE imp_member SET FCardid = dbo.FNNewId() WHERE FCardid IS NULL
UPDATE imp_member SET FMemNo =
UPDATE imp_member SET FCardNo =
UPDATE imp_member SET FCreateDate =
UPDATE imp_member SET FExpiredDate = DATEADD(YEAR,100,)
UPDATE imp_member SET FBalance = CAST(REPLACE(,',','') AS FLOAT)
SELECT FROM imp_member
UPDATE imp_member SET FMobile =
UPDATE imp_member SET FName =
UPDATE imp_member SET FGender = CASE WHEN = '' THEN 1 ELSE 0 END
UPDATE imp_member SET FBirthdayType = 'G'
UPDATE imp_member SET FState = 1
UPDATE imp_member SET FState = 4 WHERE like '%卡已注销%'
UPDATE imp_member SET Fpoint = REPLACE(,',','')
UPDATE imp_member SET FMemo =
UPDATE imp_member SET FCompId = dbo.FNCompID('001')
UPDATE imp_member SET FDeleted = 0
ALTER TABLE imp_member_card ADD FCardNo VARCHAR(50)
ALTER TABLE imp_member_card ADD FCardId BIGINT
ALTER TABLE imp_member_card ADD FCompId BIGINT
ALTER TABLE imp_member_card ADD FMemId BIGINT
ALTER TABLE imp_member_card ADD FCardTypeId BIGINT
ALTER TABLE imp_member_card ADD FDeleted BIT
ALTER TABLE imp_member_card ADD FCreateDate DATETIME
ALTER TABLE imp_member_card ADD FExpiredDate DATETIME
ALTER TABLE imp_member_card ADD FBalance DECIMAL(18,6)
ALTER TABLE imp_member_card ADD FRemainTimes DECIMAL(18,6)
ALTER TABLE imp_member_card ADD FCardTypeName VARCHAR(50)
UPDATE imp_member_card SET FCardTypeName =
UPDATE imp_member_card SET FDeleted =0
ALTER TABLE imp_member ALTER COLUMN VARCHAR(100)
ALTER TABLE imp_member_card ALTER COLUMN VARCHAR(100)
CREATE INDEX IX_IMPMEMBER_NO ON imp_member ()
CREATE INDEX IX_IMPMEMBER_CARD_NO ON imp_member_card ()
DROP TABLE #Card
SELECT * FROM #Card
--卡类别
UPDATE A
SET A.FCardTypeID = B.FId
FROM imp_member_card AS A,TMemberCardType AS B
WHERE A.FCardTypeName = B.FName
SELECT * FROM imp_member_card WHERE FCardTypeId IS NULL
--卡ID
UPDATE imp_member_card SET FCardId = dbo.FNNewId() WHERE FCardid is null
--会员ID
UPDATE A
SET A.FMemId = B.FMemId
FROM imp_member_card AS A,imp_member AS B
WHERE A. = B.
--门店
UPDATE A
SET A.FCompId = B.FCompId
FROM imp_member_card AS A,imp_member AS B
WHERE B.FMemId = A.FMemId
UPDATE imp_member_card SET FCreateDate = ,FExpiredDate =
UPDATE A
SET A.FCreateDate = B.FCreateDate,
a.FExpiredDate = dateadd(year,100,B.FCreateDate)
FROM imp_member_card AS A,imp_member AS B
WHERE A.FMemId= B.FMemId
AND A.FCreateDate IS NULL
--余额
UPDATE imp_member_card SET FBalance = 0
UPDATE imp_member_card SET FBalance = CAST(REPLACE(REPLACE(,'',''),',','') AS FLOAT)
WHERE FCardKind = 'Money'
UPDATE imp_member_card SET FRemainTimes = CAST(REPLACE(,'','') AS FLOAT)
WHERE LIKE '%次%'
UPDATE imp_member_card SET FRemainTimes = 0
WHERE LIKE '%天%'
UPDATE imp_member_card SET fcompid=1
update imp_member_card SET FCardNo =
--卡类型相同,设置为主卡
ALTER TABLE imp_member_card ADD FIsMaster BIT
UPDATE imp_member_card SET FIsMaster = 0
UPDATE A
SET A.FIsMaster = 1
FROM imp_member_card AS A,imp_member AS B
WHERE A. = B.
and A. = B.
DROP TABLE #Card
SELECT FCardNo
INTO #Card
FROM imp_member_card
WHERE FDeleted = 0
GROUP BY fcardNo
HAVING(SUM(1)) > 1
ALTER TABLE imp_member_card ADD FSeq INT IDENTITY(1,1)
ALTER TABLE imp_member_card ADD FCardIndex INT
CREATE INDEX IDX_imp_member_card_SEQ ON imp_member_card(FSeq)
UPDATE imp_member_card SET FCardIndex = 0
UPDATE A
SET A.FCardIndex = 1+ (SELECT COUNT(1) FROM imp_member_card AS B WHERE B. = A. AND (B.FIsMaster > A.FIsMaster OR B.FSeq > A.FSeq) )
FROM imp_member_card AS A
WHERE FCardNo IN(SELECT FCardNo FROM #Card)
AND A.FIsMaster = 0
update imp_member_card SET FCardNo = FCardNo + '.' + CAST(FCardINdex as varchar)
WHERE FCardNo IN(SELECT FCardNo FROM #Card)
AND FIsMaster = 0
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,
ISNULL(FMemo,'') AS FMemo,
'从博妍入' AS FCustom1,'' 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,
1 AS FState,
FCreateDate AS FCreateDate,
FExpiredDate AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FCompId AS FSaleCompId,
0 AS FSaleBillId,
ISNULL('','') AS FMemo
FROM imp_member_card
WHERE FDeleted = 0
AND FCardKind = 'Money'
AND FCardId NOT IN(SELECT FCardId FROM TMemberCard)
INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo)
SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,3,CAST(FBalance AS FLOAT),CAST(FBalance AS FLOAT),0,FCreateDate,NULL AS FExpiredDate,''
FROM imp_member_card AS A
WHERE FCardKind = 'Money'
and FDeleted = 0
AND FCardId NOT IN(SELECT FCardId FROM TMemberCardAccount)
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,'',CAST(FBalance AS FLOAT),0,CAST(FBalance AS FLOAT),0,getdate(),'从博妍中导入'
FROM imp_member_card AS A
WHERE FCardKind = 'Money'
and FDeleted = 0
AND FCardId NOT IN(SELECT FCardId FROM TMemberCardAcctHist)
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 imp_member AS A WHERE FPoint != 0
--交易历史
ALTER TABLE imp_member_rchg_hist ADD FMemId BIGINT
ALTER TABLE imp_member_rchg_hist ADD FCardId BIGINT
ALTER TABLE imp_member_rchg_hist ADD FCompId BIGINT
ALTER TABLE imp_member_cons_hist ADD FMemId BIGINT
ALTER TABLE imp_member_cons_hist ADD FCardId BIGINT
ALTER TABLE imp_member_cons_hist ADD FCompId BIGINT
UPDATE A
SET A.FMemId = B.FMemId,
A.FCardId = B.FCardId,
A.FCompId = B.FCompId
FROM imp_member_rchg_hist AS A,imp_member AS B
WHERE A.= B.
UPDATE A
SET A.FMemId = B.FMemId,
A.FCardId = B.FCardId,
A.FCompId = B.FCompId
FROM imp_member_cons_hist AS A,imp_member AS B
WHERE A.= B.
TRUNCATE TABLE imp_member_cons_hist
TRUNCATE TABLE imp_member_rchg_hist
INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo)
SELECT DBO.FNNewId(),A.FMemId,A.,A.FCardId,A.FCompId,'DR','充值','','[充值]' +,,1,,,'',''
FROM imp_member_rchg_hist AS A
WHERE ISNULL(FMemId,0) != 0
INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo)
SELECT DBO.FNNewId(),A.FMemId,A.,A.FCardId,A.FCompId,'DR','消费',,'[消费]' + ,,1,,,'',''
FROM imp_member_cons_hist AS A
WHERE ISNULL(FMemId,0) != 0
UPDATE TMemberOldTransHist SET FContent = '['+FBizType+']' + FContent WHERE FMemId IN(SELECT FMemId FROM imp_member)
DELETE A
FROM imp_member_cons_hist AS A,(SELECT ,,,,MIN(FSeq)
FROM imp_member_cons_hist
GROUP BY ,,, ) AS B
WHERE A. = B.
AND A. = B.
AND A. = B.
AND A. = B.
AND A.FSeq != B.FSeq
UPDATE T
ALTER TABLE imp_member_cons_hist ALTER COLUMN VARCHAR(100) NOT NULL
ALTER TABLE imp_member_rchg_hist ALTER COLUMN VARCHAR(100) NOT NULL
ALTER TABLE imp_member_cons_hist ADD FSeq INT IDENTITY(1,1)
ALTER TABLE imp_member_rchg_hist ADD FSeq INT IDENTITY(1,1)
DELETE TMemberOldTransHist WHERE FMemId IN(SELECT FMemId FROM imp_member)
CREATE INDEX IX_imp_memberRchgHist_CardNo ON imp_member_rchg_hist()
CREATE INDEX IX_imp_memberConsHist_CardNo ON imp_member_cons_hist()
--疗程
SELECT dbo.FNNewId() AS FId,dbo.FNNewId() AS FCourseId,FNo,FName
CREATE TABLE TImpItem
(
FId BIGINT,
FCourseId BIGINT,
FNo VARCHAR(MAX),
FName VARCHAR(MAX)
)
INSERT INTO TImpItem(FId,FCourseId,FNo,FName)
SELECT dbo.FNNewId() AS FId,dbo.FNNewId() AS FCourseId,FNo,FName
FROM (
select AS FNo, AS FName
from imp_member_card
WHERE ISNULL(FCardKind,'') = 'Course'
AND NOT IN(SELECT FName FROM TCourse)
GROUP BY
) AS A
GROUP BY FNo,FName
select AS FNo, AS FName
from imp_member_card
WHERE LIKE '%次%'
AND NOT IN(SELECT FName FROM TCourse)
GROUP BY
INSERT TItem(FId,FNo,FNoOfPad,FName,FAbbr,FTypeId,FBriefCode,FDescription,FPriceMode,FIsService,FStatTimes,FCustom1,FCustom2,FCustom3,FEnabled,FPrice,FVipPrice,FTime,FDctId,FPointMode,FPointValue,FDeptId,FAllowBooking)
SELECT FId,FNo,FName,FName,FName,0,dbo.FNGetFirstPinYin(FName),'''',1,1,1,'''','''','''',1,0,0,0,0,0,0,0,1
FROM TImpItem
WHERE FId NOT IN(SELECT FId FROM TItem)
INSERT INTO TCourse(FId,FNo,FName,FBriefCode,FItemId,FPackId,FSequence,FTypeId,FTimes,FFreeTimes,FDurable,FValidityPeriodUnit,FValidityPeriod,FCreateDate,FExpiredDate,FDescription,FEnabled,FPrice,FAmount,FCalcMode)
SELECT FCourseId AS FId,
A.FNo + 'L1',
A.FName AS FName,
'' AS FBriefCode,
A.FId AS FItemId,
0 AS FPackId,
1 AS FSequence,
(SELECT TOP 1 FId FROM TBasicType WHERE FKey = 'CourseType') AS FTypeId,
1 AS FTimes,
0 AS FFreeTimes,
0 AS FDurable,
0 AS FValidityPeriodUnit,
0 AS FValidityPeriod,
getdate() AS FCreateDate,
NULL AS FExpiredDate,
'' AS FDescription,
1 AS FEnabled,
0 AS FPrice,
0 AS FAmount,
1 AS FCalcMode
FROM TImpItem AS A
WHERE FId NOT IN(SELECT FItemId FROM TCourse)
ALTER TABLE imp_member_card ADD FItemId BIGINT
UPDATE A
SET A.FItemId = B.FId,
A.FCardTypeId = B.FCourseId
FROM TImpItem AS B,imp_member_card AS A
WHERE B.FNo = A.
AND A.FCardKind = 'Course'
SELECT * FROM imp_member_card
ALTER TABLE imp_member_card ADD FMemo VARCHAR(1000)
update imp_member_card SET FMemo = ''
update imp_member_card SET FMemo = WHERE LIKE '%天%'
--疗程
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,FCardTypeId,0,FItemId,FCompId,FRemainTimes,0,0,0,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,FMemo,1,0
FROM imp_member_card AS A
WHERE FCardKind = 'Course'
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(FCardTypeId,0),getdate(),FRemainTimes,0,0,0,FCompId,'DR','Import',0,'',0,getdate()
FROM imp_member_card AS A
WHERE FCardKind = 'Course'
DELETE TMemberCardType WHERE FName NO
SELECT * FROM imp_memberConsHist_1
SELECT * FROM imp_member_card
use KunMing_ALa_TuQiaoDian
select replace('bc 06 88 d7 30 dd de 85 bc 71 d8 86 1d 5d 8b c7 22 14 dd ae',' ','')
DELETE TMember WHERE FMemId IN(SELECT FMemId FROM imp_member)
DELETE TMemberCardAccount WHERE FMemId IN(SELECT FMemId FROM imp_member)
DELETE TMemberOldTransHist WHERE FMemId IN(SELECT FMemId FROM imp_member)
DELETE TItem WHERE FId IN(SELECT FId FROM TImpItem)
DELETE TItemSub WHERE FItemId IN(SELECT FId FROM TImpItem)
DELETE TCourse WHERE FItemId IN(SELECT FId FROM TImpItem)
DELETE TMemberCardType WHERE FId > 9
DELETE TMemberCardTypesUB
DROP TABLE imp_member_cons_hist
DELETE TImpItem
SELECT * FROM sysobjects WHERE name like 'TImp%'