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/1+1 VipInfo.sql

288 lines
8.9 KiB

use XinYang_WanMeiRenSheng
DROP TABLE VipInfo
SELECT * FROM VipInfo
where cardNum IN( '00210','00210_20190525063410')
SELECT * FROM VipInfo
WHERE IsLoss = 'ÍË¿¨'
SELECT * FROM discountCard
WHERE id IN
select
--»áÔ±
ALTER TABLE vipInfo ADD mem_id BIGINT
ALTER TABLE vipInfo ADD card_id BIGINT
ALTER TABLE vipInfo ADD card_type_name VARCHAR(100)
ALTER TABLE vipInfo ADD mem_no VARCHAR(50)
ALTER TABLE vipInfo ADD card_No VARCHAR(50)
ALTER TABLE vipInfo ADD name VARCHAR(50)
ALTER TABLE vipInfo ADD gender INT
ALTER TABLE vipInfo ADD mobile VARCHAR(50)
ALTER TABLE vipInfo ADD birthday_type VARCHAR(50)
ALTER TABLE vipInfo ADD birthday DATETIME
ALTER TABLE vipInfo ADD comp_id BIGINT
ALTER TABLE vipInfo ADD card_type_id BIGINT
ALTER TABLE vipInfo ADD memo VARCHAR(MAX)
ALTER TABLE vipInfo ADD balance DECIMAL(18,6)
ALTER TABLE vipInfo ADD balance2 DECIMAL(18,6)
ALTER TABLE vipInfo ADD point DECIMAL(18,6)
ALTER TABLE vipInfo ADD deleted bit
ALTER TABLE vipInfo ADD create_time DATETIME
ALTER TABLE vipInfo ADD Pur_Times DECIMAL(18,6)
ALTER TABLE vipInfo ADD Used_Pur_Times DECIMAL(18,6)
ALTER TABLE vipInfo ADD Pur_Amount DECIMAL(18,6)
ALTER TABLE vipInfo ADD Item_Id BIGINT
ALTER TABLE vipInfo ADD Adjust_Price DECIMAL(18,6)
UPDATE vipInfo SET deleted = 0
UPDATE vipInfo SET deleted = 1 WHERE IsLoss = 'ÍË¿¨'
UPDATE vipInfo SET mem_id = dbo.FNNewId()
UPDATE vipInfo SET card_id = dbo.FNNewId()
UPDATE vipInfo SET mem_no = CardNum
UPDATE vipInfo SET card_no = CardNum
UPDATE vipInfo SET mobile = ISNULL(VipMobile,'')
UPDATE vipInfo SET birthday_type ='G'
UPDATE vipInfo SET birthday_type ='L' WHERE Isnull(BirthNote,'') = 'Å©Àú'
UPDATE vipInfo SET birthday = VipBirth WHERE ISNULL(VipBirth,'') != ''
UPDATE vipInfo SET name = VipName
UPDATE vipInfo SET name = mobile WHERE name is null
UPDATE vipInfo SET name = card_no WHERE name is null
UPDATE vipInfo SET memo = vipNote
UPDATE vipInfo SET comp_id = 1
UPDATE vipInfo SET gender = 0
UPDATE vipInfo SET gender = 1 where sex = 'ÄÐ'
UPDATE vipInfo SET create_time = createTime
drop table TImpCardType
SELECT dbo.FNNewId() AS id, CardName AS name,
CASE WHEN CardType ='¼Æ´Î¿¨' THEN 3 ELSE 1 END AS value_type
INTO TImpCardType
FROM vipInfo
GROUP BY CardName ,CardType
SELECT dbo.FNNewId() AS id,CardName AS name ,1 as value_type
INTO TImpCardType
FROM VipInfo
WHERE CardType = '´¢ÕÛ¿¨'
AND deleted = 0
GROUP BY CardName
select * from TMemberCardType
delete TMemberCardType where fid in(5175400831544352678
,7837040691303887946)
--¿¨Àà±ð
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 =Id,name,name as name,value_type,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 TImpCardType
UPDATE a
SET a.card_type_id = B.id
FROM vipInfo AS A,TImpCardType AS B
WHERE A.CardName = B.name
UPDATE vipInfo SET balance = cardMoney
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_time 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,
ISNULL(memo,'') AS FMemo,
'' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5
from vipInfo
WHERE deleted = 0
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId,
FMemo)
SELECT
card_id AS FId,
mem_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_time AS FCreateDate,
dateadd(year,100,create_time) AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
comp_id AS FSaleCompId,
0 AS FSaleBillId,
'' AS FMemo
FROM vipInfo
WHERE deleted = 0
AND cardType = '´¢ÕÛ¿¨'
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_time,NULL AS FExpiredDate,''
FROM vipInfo
WHERE cardType = '´¢ÕÛ¿¨'
AND deleted = 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(),'´ÓÀÏϵͳÖе¼Èë'
FROM vipInfo AS A
WHERE cardType = '´¢ÕÛ¿¨'
AND deleted = 0
SELECT CardName as name ,dbo.FNNewId() AS id,dbo.FNNewId() AS course_id
INTO TImpItem
FROM VipInfo
WHERE CardType = '¼Æ´Î¿¨'
AND deleted = 0
GROUP BY CardName
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 id,replace(name,'-',''),replace(name,'-',''),name,name,0,dbo.FNGetFirstPinYin(name),'''',1,1,1,'''','''','''',1,0,0,0,0,0,0,0,1
FROM TImpItem
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,
replace(name,'-','') + '',
I.name AS FName,
'' AS FBriefCode,
I.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 TImpItem AS I
UPDATE A
SET A.card_type_id = B.course_id,
a.item_id = b.id
FROM VipInfo AS A,TImpItem AS B
WHERE B.name = A.CardName
AND A.CardType = '¼Æ´Î¿¨'
UPDATE VipInfo SET pur_times = CardTimes,used_pur_times = 0,pur_amount = 0,adjust_price = 0
SELECT * FROM VipInfo WHERE CardName = 'Ä꿨'
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,card_type_id,0,item_id,comp_id,Pur_Times,ISNULL(Pur_Amount,0),0,used_pur_times,0,Create_time,null,'DR.Import',0,0,0,'',1,ISNULL(Adjust_Price,0)
FROM VipInfo
--WHERE FCourseId IS NOT NULL
WHERE CardType = '¼Æ´Î¿¨'
and deleted = 0
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,card_type_id,FTime = getdate(),Pur_Times,used_pur_times,0,0,
comp_id,
'DR','Import',0,'',0
FROM VipInfo
WHERE CardType = '¼Æ´Î¿¨'
and deleted = 0
ALTER TABLE SaleMain ADD mem_id BIGINT
ALTER Table SaleMain ADD comp_id BIGINT
UPDATE A
SET A.mem_id = b.mem_id,
A.comp_id = b.comp_id
FROM SaleMain AS A,vipInfo AS B
WHERE A.VipCode = B.VipCode
INSERT dbo.TMemberOldTransHist(FId,FCompId,FMemId,FTime,FCardId,FBIllType,FBizType,FTransNo,FCOntent,FPrice,FQuantity,FAmount,FPayment,Femployee,FMemo)
SELECT dbo.FNNewId(), comp_id,a.mem_id, a.createTime , 0,'DR' ,'Import' ,a.saleNum,b.itemsName,b.salePrice, b.saleAmount , b.saleMoney , '','',''
FROM saleDetail AS B,saleMain AS A
WHERE A.saleNum = b.saleNum
AND isnull(a.mem_id,0 )!= 0