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/嘉艺_单机2.sql

379 lines
11 KiB

1 year ago
use TaiYuan_YiYi
SELECT * FROM Base_card
SELECT * FROM TConsumeBill
UPDATE TMemberCardType SET FAcctId2= 10
SELECT * FROM TPayAccount
SELECT * FROM TItem
SELECT * FROM B_KH
SELECT * FROM B_KH_JC
SELECT * FROM TItem
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ALTER TABLE Base_card ADD FID BIGINT
UPDATE Base_card SET FId = 10000 + ID
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,'JY' + NAME,NAME as name,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 Base_card
WHERE ID IN(SELECT HYCARD FROM B_KCARD)
ALTER TABLE B_KH ADD mem_id BIGINT
ALTER TABLE B_KH ADD mem_no VARCHAR(50)
ALTER TABLE B_KH ADD gender INT
ALTER TABLE B_KH ADD mobile VARCHAR(50)
ALTER TABLE B_KH ADD birthday_type VARCHAR(50)
ALTER TABLE B_KH ADD birthday DATETIME
ALTER TABLE B_KH ADD comp_id BIGINT
ALTER TABLE B_KH ADD point DECIMAL(18,6)
ALTER TABLE B_KH ADD create_date datetime
ALTER TABLE B_KH ADD expire_date datetime
ALTER TABLE B_KCARD ADD card_No VARCHAR(50)
ALTER TABLE B_KCARD ADD create_date datetime
ALTER TABLE B_KCARD ADD expire_date datetime
ALTER TABLE B_KCARD ADD card_id BIGINT
ALTER TABLE B_KCARD ADD card_type_name VARCHAR(100)
ALTER TABLE B_KCARD ADD balance DECIMAL(18,6)
ALTER TABLE B_KCARD ADD balance2 DECIMAL(18,6)
ALTER TABLE B_KCARD ADD comp_id BIGINT
ALTER TABLE B_KCARD ADD mem_id BIGINT
ALTER TABLE B_KCARD ADD memo VARCHAR(MAX)
ALTER TABLE B_KCARD ADD card_type_id BIGINT
UPDATE B_KH SET mem_id = dbo.FNNewId() WHERE mem_id IS NULL
UPDATE B_KCARD SET card_id = dbo.FNNewId() WHERE card_id IS NULL
UPDATE B_KCARD SET card_no = CARDNO
UPDATE B_KCARD SET Balance = KYE
UPDATE B_KCARD SET Balance2 = ZSYE
UPDATE B_KCARD SET memo = ISNULL(KSM,'')
UPDATE B_KCARD SET Create_date = rdate
UPDATE B_KCARD SET expire_date = dateadd(year,100,create_date)
UPDATE A
SET A.mem_id = B.mem_id
FROM B_KCARD AS A,B_KH AS B
WHERE A.KHID = B.ID
UPDATE A
SET A.mem_no = B.card_no,
A.create_date = b.create_date
FROM B_KH AS A,B_KCARD AS B
WHERE A.mem_id = b.mem_id
UPDATE B_KH SET mem_No = tel where isnull(mem_no, '') = ''
UPDATE A
SET A.card_no = B.mem_no
FROM B_KCARD AS A,B_KH AS B
WHERE A.KHID = B.ID
AND isnull(a.card_no,'') = ''
UPDATE B_KH SET mobile = TEL
select * from B_KCARD WHERE khid = 172
SELECT khid from b_kcard
group by khid
HAVING SUM(1) > 1
SELECT * FROM B_KCARD WHERE CARDNO =''
UPDATE B_KH SET gender = CASE WHEN sex = 1001 THEN 1 ELSE 0 END
UPDATE A SET A.Point = B.KJF
FROM B_KH AS A,B_KCARD AS B
WHERE A.ID = B.KHID
UPDATE B_KH SET birthday_type = 'G'
UPDATE B_KCARD SET comp_id = dbo.FNCompId('002')
UPDATE B_KH SET comp_id = dbo.FNCompId('002')
SELECT * FROM B_KCARD WHERE card_type_id is null
UPDATE A
SET A.card_type_id = B.FId
FROM B_KCARD AS A,BASE_CARD AS B
WHERE A.HYCARD = B.ID
select * from BASE_CARD
select * from B_KCARD
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 mem_id AS FMemId,
mem_no AS FMemNo,
name AS FName,
dbo.FNGetFirstPinYin(name),
0 AS FTypeId,
comp_id AS FCompId,
create_date AS FCreateDate,
gender AS FGender,
birthday_type AS FBirthdayType,
birthday AS FBirthday,
'' AS FTelephone,
ISNULL(mobile,'') AS FMobilePhone,
'' AS FQQ,
'' AS FWeChat,
'' AS FIdCard,
'' AS FEmail,
'' AS FAddress,
0 AS FProId,
'' AS FCPW,
'' AS FQPW,
0 AS FChargeEmpId,
0 AS FPoint,
1 AS FRecvConsSMS,
1 AS FRecvBulkSMS,
'' AS FMemo,
'' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5
from B_KH
WHERE mem_No IN(SELECT FMemNO FROM TMember )
SELECT mem_No FROM B_KH
GROUP BY mem_no
HAVING SUM(1) > 1
UPDATE B_KH SET mem_no = 'JY' + mem_no WHERE mem_No IN(SELECT FMemNO FROM TMember )
UPDATE B_KCARD SET card_no = 'JY' + card_no WHERE card_no IN(SELECT FMemNO FROM TMember )
delete TMember WHERE FMemId IN(SELECT mem_id FROM B_KH)
drop table #Card
SELECT mem_no into #Card
FROM B_KH
GROUP BY mem_no
HAVING(SUM(1)) > 1
ALTER TABLE B_KH ADD seq INT IDENTITY
ALTER TABLE B_KH ADD idx INT
UPDATE A
SET A.idx = 1+(SELECT COUNT(1) FROM B_KH AS B WHERE A.mem_no = B.mem_no AND (A.create_date > B.create_date OR (A.create_date = B.create_date AND (A.seq > B.seq) )))
FROM B_KH AS A
UPDATE B_KH SET mem_no = mem_no + '_' + CAST(idx AS VARCHAR)
WHERE mem_no IN( SELECT mem_no FROM #Card)
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId,
FMemo)
SELECT
card_id AS FId,
CARD_NO AS FNo,
card_type_id AS FTypeId,
(SELECT FValueType FROM TMemberCardType WHERE FId = card_type_id) AS FValueType,
comp_id AS FCompId,
mem_id AS FMemId,
1 AS FState,
create_date AS FCreateDate,
expire_date AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
comp_id AS FSaleCompId,
0 AS FSaleBillId,
memo AS FMemo
FROM B_KCARD
WHERE isdel = 0
and mem_id not in(select FMemId FROM TMember)
INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo)
SELECT mem_id,dbo.FNNewId(),card_id AS card_id,3,balance,balance,0,create_date,NULL AS FExpiredDate,''
FROM B_KCARD
WHERE isdel = 0
INSERT TMemberCardAcctHist(FId,FMemId,FCardId,FAcctId,FTime,FCardTypeId,FCompId,FBillType,FBizType,FTransId,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo)
select dbo.FNNewId(),A.mem_id,A.card_id,3,getdate(),A.card_type_id,A.comp_id,'DR','Import',0,'',A.balance,0,A.balance,0,getdate(),'<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD>'
FROM B_KCARD AS A
WHERE isdel = 0
SELECT * FROM BASE_FW
ALTER TABLE BASE_FW ADD item_id BIGINT
ALTER TABLE BASE_FW ADD course_id BIGINT
UPDATE BASE_FW SET item_id = dbo.FNNewId()
UPDATE BASE_FW SET course_id = dbo.FNNewId()
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 item_id,'001' + bm,name,name,name,0,dbo.FNGetFirstPinYin(name),'',1,1,1,'','','',1,FJG,FJG,0,0,0,0,0,1
FROM BASE_FW
INSERT INTO TCourse(FId,FNo,FName,FBriefCode,FItemId,FPackId,FSequence,FTypeId,FTimes,FFreeTimes,FDurable,FValidityPeriodUnit,FValidityPeriod,FCreateDate,FExpiredDate,FDescription,FEnabled,FPrice,FAmount,FCalcMode)
SELECT course_id AS FId,
'001'+I.bm + '',
I.name AS FName,
'' AS FBriefCode,
I.item_id 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 BASE_FW AS I
ALTER TABLE B_KH_JC ADD mem_id BIGINT
ALTER TABLE B_KH_JC ADD card_id BIGINT
ALTER TABLE B_KH_JC ADD course_id BIGINT
ALTER TABLE B_KH_JC ADD remain_Times DECIMAL(18,6)
ALTER TABLE B_KH_JC ADD Used_Pur_Times DECIMAL(18,6)
ALTER TABLE B_KH_JC ADD Pur_Amount DECIMAL(18,6)
ALTER TABLE B_KH_JC ADD Comp_Id BIGINT
ALTER TABLE B_KH_JC ADD Item_Id BIGINT
ALTER TABLE B_KH_JC ADD Pur_Times DECIMAL(18,6)
ALTER TABLE B_KH_JC ADD Adjust_Price DECIMAL(18,6)
ALTER TABLE B_KH_JC ADD create_date datetime
ALTER TABLE B_KH_JC ADD expire_date datetime
UPDATE B_KH_JC SET card_id = dbo.FNNewId()
UPDATE A
SET A.item_id = B.item_id,
A.Course_Id = B.Course_Id
FROM B_KH_JC AS A,BASE_FW AS B
WHERE A.JCXM = B.BM
SELECT * FROM B_KH_JC WHERE BM = 'k582'
UPDATE A
SET A.mem_id = B.mem_id,
a.create_date = b.create_date
FROM B_KH_JC AS A,B_KH AS B
WHERE A.BM = B.bm
UPDATE B_KH_JC SET pur_Times = ISNULL(yc,0) ,remain_Times = ISNULL(YC,0) ,
used_pur_times = ISNULL(yc,0)-ISNULL(YC,0), adjust_price = isnull(jg,0)
UPDATE B_KH_JC SET comp_id = dbo.FNCompId('001')
DELETE TMemberCourse
INSERT TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FPurAmount,FFreeTimes,FUsedPurTimes,FFreeAmount,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice)
SELECT card_id,mem_id,course_id,0,item_id,comp_id,Pur_Times,ISNULL(Pur_Amount,0),0,used_pur_times,0,Create_Date,Expire_Date,'DR.Import',0,0,0,'<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>',1,ISNULL(Adjust_Price,0)
FROM B_KH_JC
WHERE course_id IS NOT NULL
INSERT INTO TMemberCourseLog(FId,FMemId,FCardId,FPackId,FCourseId,FTime,FInPurTimes,FInFreeTimes,FOutPurTimes,FOutFreeTimes,
FCompId,
FBillType,FBizType,FBillId,FBillNo,FBillDetailId)
SELECT dbo.FNNewId(),Mem_Id,card_Id,0,Course_Id,FTime = getdate(),Pur_Times,Pur_Times - Remain_Times,0,0,
comp_id,
'DR','Import',0,'',0
FROM B_KH_JC
WHERE course_id IS NOT NULL
INSERT TItemSub(FId,FCompId,FItemId,FPrice,FVipPrice,FTime,FDctId,FPointMode,FPointValue,FDeptId,FAllowBooking,FEnabled)
SELECT dbo.FNNewId(),C.FId,I.FId,I.FPrice,I.FVipPrice,I.FTime,I.FDctId,I.FPointMode,I.FPointValue,I.FDeptId,I.FAllowBooking,I.FEnabled
FROM TItem AS I,TCompany AS C
WHERE I.FId != 0
AND C.FId != 0
--AND C.FNo = '009'
AND NOT EXISTS(SELECT TOP 1 1 FROM TItemSub AS B WHERE B.FCompId = C.FId AND B.FItemId = I.FId)
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)
SELECT * FROM B_KH WHERE CARDNO = '5200030'
SELECT * FROM B_KH_JC WHERE BM = 'K582'