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

403 lines
14 KiB

SELECT FROM imp_member_list
select ,,,,,,ISNULL(,0) as INTO imp_member
FROM imp_member_list
group by ,,,,,,ISNULL(,0)
SELECT FROM imp_member
GROUP BY
HAVING SUM(1) > 1
select ,,,,,,,使
into imp_member_card
FROM imp_Member_list
group by ,,,,,,,使
select from imp_Member_card
where Is not null
group by
having sum(1) > 1
SELECT , ,[   #] as
INTO imp_member_card_account
FROM imp_Member_list
where Is not null
GROUP BY ,,[   #]
ALTER TABLE imp_member ADD FMemId BIGINT
ALTER TABLE imp_member ADD FCardNo VARCHAR(50)
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 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 FBirthday DATETIME
ALTER TABLE imp_member ADD FBirthdayType CHAR
ALTER TABLE imp_member ADD FCustom1 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 FCardTypeId BIGINT
ALTER TABLE imp_member_card ADD FCourseId BIGINT
ALTER TABLE imp_member_card ADD FRemainTimes INT
ALTER TABLE imp_member_card ADD FPurTimes INT
ALTER TABLE imp_member_card ADD FPurAmount DECIMAL(18,6)
ALTER TABLE imp_member_card ADD FItemId BIGINT
ALTER TABLE imp_member_card ADD FCreateDate DATETIME
ALTER TABLE imp_member_card ADD FExpiredDate DATETIME
ALTER TABLE imp_member_card ADD FCompId BIGINT
ALTER TABLE imp_member_card ADD FCardId BIGINT
ALTER TABLE imp_member_card ADD FMemo VARCHAR(1000)
ALTER TABLE imp_member_card ADD FArrear DECIMAL(18,6)
ALTER TABLE imp_member_card ADD FPoint DECIMAL(18,6)
ALTER TABLE imp_member_card ADD FBirthday DATETIME
ALTER TABLE imp_member_card ADD FBirthdayType CHAR
ALTER TABLE imp_member_card ADD FCustom1 VARCHAR(100)
ALTER TABLE imp_member_card ADD FCardTYpeName VARCHAR(100)
ALTER TABLE imp_member_card ADD FCardTypeNo VARCHAR(100)
ALTER TABLE imp_member_card_account ADD FMemId BIGINT
ALTER TABLE imp_member_card_account ADD FCardID BIGINT
ALTER TABLE imp_member_card_account ADD FACCTId BIGINT
ALTER TABLE imp_member_card_account ADD FCreateDate DATETIME
ALTER TABLE imp_member_card_account ADD FBalance DECIMAL(18,6)
--初始化卡类别
UPDATE imp_member_card SET FCardTYpeNo = left(,CHARINDEX('-',)-1)
UPDATE imp_member_card SET FCardTYpeName = substring(,CHARINDEX('-',) + 1,len())
DROP TABLE TImpCardType
CREATE TABLE TImpCardType
(
FId BIGINT,
FNo VARCHAR(50),
FName VARCHAR(50),
FType VARCHAR(50),
FValueType INT
)
INSERT TImpCardType(FId,FNo,FName,FValueType)
SELECT dbo.FNNewId(),'Y' + FCardTypeNo,FCardTypeName,1
FROM imp_member_card
WHERE IS NOT NULL
GROUP BY FCardTYpeNo,FCardTYpeName
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 =FId,FNo,FName,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 TImpCardType
SELECT * FROM imp_member
UPDATE imp_Member SET FMemID = dbo.FNNewId()
UPDATE imp_Member SET FCreateDate =
UPDATE imp_Member SET FGender = case when = '' then 1 else 0 end
UPDATE imp_Member SET FBirthday =
UPDATE imp_Member SET FPoint =
UPDATE imp_member SET FMemNo=
UPDATE imp_member SET FName =
UPDATE imp_member SET FMobile =
UPDATE imp_member SET FBirthdayType = 'G'
update imp_member_card SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL
UPDATE A SET A.FMemId = B.FMemId
FROM imp_member_card AS A,imp_member AS B
WHERE A.= b.
--卡号
UPDATE imp_member_card SET FCardId = dbo.FNNewId()
UPDATE imp_member_card SET FCardNo =
UPDATE imp_member_card SET FCreateDate =
UPDATE imp_member_card SET FExpiredDate =
UPDATE A
SET A.FCardTypeId = B.FId
FROM imp_member_card AS A,TImpCardType AS B
WHERE 'Y'+ A.FCardTypeNo = B.Fno
SELECT * FROM imp_member_card
--卡门店
UPDATE imp_member SET FCardId = dbo.FNCompId('001')
UPDATE imp_member_card SET FCompId = dbo.FNCompId('001')
--余额
UPDATE imp_member_card_account SET = REPLACE(,char(10),'')
UPDATE imp_member_card_account SET = REPLACE(,char(13),'')
UPDATE imp_member_card_account SET FBalance = cast( as float)
select * from imp_member_card_account
UPDATE imp_member_card_account SET = REPLACE(,' ','')
UPDATE imp_member_card_account SET = REPLACE(,' ','')
UPDATE imp_member_card_account SET = REPLACE(,char(10),'')
UPDATE imp_member_card_account SET = REPLACE(,char(13),'')
UPDATE A
SET A.FMemId = B.FMemId,
A.FCardId = B.FCardID,
A.FCreateDate = B.FCreateDate
FROM imp_member_card_account AS A,imp_member_card AS B
WHERE a.= B.
UPDATE A
SET A.FAcctId = B.FId
FROM imp_member_card_account AS A,TPayAccount AS B
WHERE A. = B.FName
SELECT dbo.FNNewId() AS FId, AS FName into imp_account FROM imp_member_card_account
WHERE FAcctId IS NULL
GROUP BY
INSERT TPayAccount(FId,FNo,FName,FDescription,FIsAccount,FAllowEdit,FItemBizRate,FGoodsBizRate,FCardBizRate,FItemPerfRate,FGoodsPerfRate,FCardPerfRate,FItemPointRate,FGoodsPointRate,FCardPointRate,FIsCashIncome,FIsBizIncome,FIsCashPerf,FIsLabor,FCourseIsLabor,FEnabled,FOrder,FMemberDisplay)
SELECT A.FId,A.FName,A.FName ,'导入账户',FIsAccount,FAllowEdit,FItemBizRate,FGoodsBizRate,FCardBizRate,FItemPerfRate,FGoodsPerfRate,FCardPerfRate,FItemPointRate,FGoodsPointRate,FCardPointRate,FIsCashIncome,FIsBizIncome,FIsCashPerf,FIsLabor,FCourseIsLabor,FEnabled,FOrder,FMemberDisplay
FROM TPayAccount AS B,imp_account AS A
WHERE b.fid = 3
UPDATE imp_member_card SET FCreateDate = DATEADD(second,cast(opendate as bigint) / 1000,'1970-01-01 00:00:00')
UPDATE imp_member_card SET FExpiredDate = DATEADD(YEAR,100,FCreateDate)
UPDATE A
SET A.FExpiredDate = DATEADD(minute,s ,'1970-01-01 00:00:00')
FROM imp_member_card AS A,(
SELECT id,(cast(invaliddate as bigint) / cast(1000 as bigint)) / 60 as s
FROM imp_member_card
where invaliddate != ''
) AS B
WHERE A.id = B.id
SELECT * FROM imp_member_card WHERE cast(presentfee as float)> 0.0
--会员编号
UPDATE A
SET A.FMemNo = B.FCardNo
FROM imp_member AS A,imp_member_card AS B
WHERE A.Id = b.memberid
--shopId
UPDATE A
SET A.FCompId = B.FCompID
FROM imp_member AS A,TImpCompany AS B
WHERE A.shopId = B.shopId
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,
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,
ISNULL( FPoint,0) 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
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FCardFaceNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId,
FMemo)
SELECT
FCardId AS FId,
FCardNo AS FNo,
FCardNo AS FFaceNo,
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,
ISNULL(FRemainTimes,0) AS FTotalTimes,
0 AS FUsedTimes,
FCompId AS FSaleCompId,
0 AS FSaleBillId,
ISNULL(FMemo,'' ) AS FMemo
FROM imp_member_card
WHERE is not null
INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo)
SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,FAcctId,FBalance,FBalance,0,FCreateDate,NULL AS FExpiredDate,''
FROM imp_member_card_account AS A
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,FAcctId,getdate(),B.FCardTypeId,B.FCompId,'DR','Import',0,'',A.FBalance,0,A.FBalance,0,getdate(),'导入'
FROM imp_member_card_account AS A,imp_member_card as b
where a.fcardid = b.fcardid
--疗程
--储值卡里面的疗程卡
SELECT dbo.FNNewId() AS item_id,dbo.FNNewId() AS course_id,FCardTypeName AS name,FCardTypeNo AS no
INTO imp_item
FROM imp_member_card
WHERE is null
GROUP BY FCardTypeNo,FCardTypeName
ALTER TABLE imp_member_card ADD FUsedTimes INT
ALTER TABLE imp_member_card ADD FAdjustPrice DECIMAL(18,6)
UPDATE imp_member_card SET FPurTimes = CAST(使 AS FLOAT)+CAST( AS FLOAT)
UPDATE imp_member_card SET FUsedTimes = 使
UPDATE imp_member_card SET FPurAmount =
UPDATE imp_member_card SET FAdjustPrice = FPurAmount / FPurTimes where FPurTimes > 0
UPDATE imp_member_card SET FMemo = ''
UPDATE A
SET A.FCourseId = B.course_id,
A.FItemId = B.item_id
FROM imp_member_card AS A,imp_item AS B
WHERE A.FCardTypeName = b.name
AND is null
--疗程
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,FPurTimes,FUsedTimes,FPurAmount,0,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,FMemo,1,FAdjustPrice
FROM imp_member_card AS A
where is null
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(),FPurTimes,0,FUsedTimes,0,FCompId,'DR','Import',0,'',0,getdate()
FROM imp_member_card AS A
where is null
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,''+no,name,name,name,0,dbo.FNGetFirstPinYin(name),'',1,1,1,'','','',1,0,0,0,0,0,0,0,1
FROM imp_item
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,
'' + A.no + '',
A.name AS FName,
'' AS FBriefCode,
A.item_id AS FItemId,
0 AS FPackId,
1 AS FSequence,
0,--(SELECT TOP 1 FId FROM TBasicType WHERE FKey = 'CourseType') AS FTypeId,
ISNULL(0,0) AS FTimes,
0 AS FFreeTimes,
0 AS FDurable,
1 AS FValidityPeriodUnit,
100 AS FValidityPeriod,
getdate() AS FCreateDate,
NULL AS FExpiredDate,
'' AS FDescription,
1 AS FEnabled,
0 AS FPrice,
0 AS FAmount,
1 AS FCalcMode
FROM imp_item AS A
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 NOT EXISTS(SELECT TOP 1 1 FROM TItemSub AS B WHERE B.FCompId = C.FId AND B.FItemId = I.FId)
AND I.FId IN(SELECT item_id FROM imp_item)
AND C.FNo in('001','000')
INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo)
SELECT DBO.FNNewId(),A.mem_id,dateadd(second,cast(createDate as bigint)/1000,'1970-01-01'),0,A.comp_id,'DR','Import',billno,comment,consumefee,1,consumefee,'',isnull('','') + ',' + isnull('','') + ',' + isnull('',''),''
FROM imp_member_trans_hist AS A
order by createDate
select * from imp_member_trans_hist