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/木一/SQLQuery19.sql

270 lines
8.0 KiB

SELECT * FROM TImpMember
ALTER TABLE TImpMember ADD FMemId BIGINT
ALTER TABLE TImpMember ADD FCardNo VARCHAR(50)
ALTER TABLE TImpMember ADD FMemNo VARCHAR(50)
ALTER TABLE TImpMember ADD FName VARCHAR(50)
ALTER TABLE TImpMember ADD FGender INT
ALTER TABLE TImpMember ADD FMobile VARCHAR(50)
ALTER TABLE TImpMember ADD FCardTypeId BIGINT
ALTER TABLE TImpMember ADD FCourseId BIGINT
ALTER TABLE TImpMember ADD FBalance DECIMAL(18,6)
ALTER TABLE TImpMember ADD FRemainTimes INT
ALTER TABLE TImpMember ADD FPurTimes INT
ALTER TABLE TImpMember ADD FPurAmount DECIMAL(18,6)
ALTER TABLE TImpMember ADD FItemId BIGINT
ALTER TABLE TImpMember ADD FCreateDate DATETIME
ALTER TABLE TImpMember ADD FExpiredDate DATETIME
ALTER TABLE TImpMember ADD FCompId BIGINT
ALTER TABLE TImpMember ADD FCardId BIGINT
ALTER TABLE TImpMember ADD FMemo VARCHAR(1000)
ALTER TABLE TImpMember ADD FArrear DECIMAL(18,6)
ALTER TABLE TImpMember ADD FPoint DECIMAL(18,6)
ALTER TABLE TImpMember ADD FBirthday DATETIME
ALTER TABLE TImpMember ADD FBirthdayType CHAR
UPDATE TImpMember SET FMemId = dbo.FNNewId() WHERE FMemid IS NULL
UPDATE TImpMember SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL
UPDATE TImpMember SET FCardNo = '000' +
UPDATE TImpMember SET FMemNo = FCardNo
UPDATE TImpMember SET FName =
UPDATE TImpMember SET FMobile =
UPDATE TImpMember SET FCardNo =FMobile WHERE FCardNo IS NULL
UPDATE TImpMember SET FGender = CASE WHEN = '' THEN 1 ELSE '0' END
UPDATE TImpMember SET FBalance =
UPDATE TImpMember SET FCreateDate =
UPDATE TImpMember SET FExpiredDate = '9999-12-31'
UPDATE TImpMember SET FArrear =
UPDATE TImpMember SET FMemo = ISNULL(REM,'') + '' + ISNULL(ACCREM,'')
UPDATE TImpMember SET FPoint =
UPDATE A
SET A.FCardTypeId = B.FId
FROM TImpMember AS A,TMemberCardType AS B
WHERE A. = B.FName
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,
1 AS FCompId,
ISNULL(FCreateDate ,'1900-01-01') AS FCreateDate,
FGender AS FGender,
'G' 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 TImpMember
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FCardFaceNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId,
FMemo)
SELECT
FCardId AS FId,
FMemno AS FNo,
FMemno AS FFaceNo,
FCardTypeId AS FTypeId,
(SELECT FValueType FROM TMemberCardType WHERE FId = FCardTypeId) AS FValueType,
1 AS FCompId,
FMemId AS FMemId,
1 AS FState,
ISNULL(FCreateDate,1900) AS FCreateDate,
FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
1 AS FSaleCompId,
0 AS FSaleBillId,
'' AS FMemo
FROM TImpMember
WHERE FCardTypeId IS NOT NULL
INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo)
SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,3,FBalance,FBalance,0,FCreateDate,DATEADD(year,1, FCreateDate) AS FExpiredDate,''
FROM TImpMember AS A
WHERE FCardTypeId IS NOT NULL
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,1,'DR','Import',0,'',A.FBalance,0,A.FBalance,0,getdate(),'从Excel中导入'
FROM TImpMember AS A
WHERE FCardTypeId IS NOT NULL
select * from TIMpTransLog
DELETE TIMpTransLog WHERE IS NULL
OR = '合计'
DELETE TIMpTransLog WHERE
ALTER TABLE TImpTransLog ADD
FMemId BIGINT,
FId BIGINT,
FTime DATETIME,
FCompId BIGINT,
FEmployee VARCHAR(1000),
FContentText VARCHAR(1000),
ALTER TABLE TImpTransLog ADD
FBizType VARCHAR(20)
SELECT * FROM TImpTransLog
UPDATE A
SET A.FMemId = B.FMemId,
A.FCardId = B.FCardId
FROM TImpTransLog AS A,TImpMember3 AS B
WHERE A. =B.FCardNo
AND B.FCardNo = 'A020935'
UPDATE TImpTransLog SET FId = dbo.FNNewId(),
FTime = ,
FEmployee = '',
FContentText = ,
FAmount = ,
FCompId = (SELECT FId FROM TCompany WHERE FNo = '002')
SELECT * FROM TImpTransLog WHERE FMemId IS NULL
SELECT * FROM TImpMember3 WHERE FMemNo = 'A020935'
SELECT * FROM TImpTransLog WHERE = '13883619808'
SELECT * FROM TImpMember WHERE FMobile = '13883619808'
--疗程
CREATE TABLE TImpCourse(FMobile VARCHAR(20),FCourseNo VARCHAR(20),FTimes DECIMAL(18,6))
INSERT TImpCourse(FMobile,FCourseNo,FTimes)
SELECT '13983924458','101L1','3'
UNION ALL SELECT '13628327912','201L1','9'
UNION ALL SELECT '18602392097','201L1','8'
UNION ALL SELECT '15922747897','101L1','9'
UNION ALL SELECT '13368294521','101L1','8'
UNION ALL SELECT '13708323481','201L1','9'
UNION ALL SELECT '13883531980','101L1','7'
UNION ALL SELECT '13996168768','201L1','9'
UNION ALL SELECT '15025322817','101L1','7'
UNION ALL SELECT '15111976180','201L1','10'
UNION ALL SELECT '15123978812','101L1','10'
UNION ALL SELECT '13508353813','101L1','9'
SELECT * FROM TImpCourse
ALTER TABLE TImpCourse ADD FId BIGINT
ALTER TABLE TImpCourse ADD FCourseId BIGINT
ALTER TABLE TImpCourse ADD FRemainTimes DECIMAL(18,6)
ALTER TABLE TImpCourse ADD FUsedPurTimes DECIMAL(18,6)
ALTER TABLE TImpCourse ADD FPurAmount DECIMAL(18,6)
ALTER TABLE TImpCourse ADD FCompId BIGINT
ALTER TABLE TImpCourse ADD FItemId BIGINT
ALTER TABLE TImpCourse ADD FMemId BIGINT
ALTER TABLE TImpCourse ADD FCreateDate DATETIME
ALTER TABLE TImpCourse ADD FExpiredDate DATETIME
ALTER TABLE TImpCourse ADD FPurTimes DECIMAL(18,6)
ALTER TABLE TImpCourse ADD FAdjustPrice DECIMAL(18,6)
UPDATE A
SET A.FMemId = B.FMemId,
A.FCompId = B.FCompId
FROM TImpCourse AS A,TMember AS B
WHERE A.FMobile = B.FMobilePhone
AND A.FMemId IS NULL
UPDATE TImpCourse SET FId = dbo.FNNewId()
--编号
UPDATE A
SET A.FCourseId = C.FId,
A.FItemId = C.FItemId
FROM TImpCourse AS A, TCourse AS C
WHERE A.FCourseNo = C.FNo
UPDATE TImpCourse SET FPurTimes = FTimes
INSERT TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FPurAmount,FFreeTimes,FUsedPurTimes,FFreeAmount,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice)
SELECT FId,FMemId,FCourseId,0,FItemId,FCompId,FPurTimes,ISNULL(FPurAmount,0),0,FUsedPurTimes,0,getdate(),'9999-12-31','DR.Import',0,0,0,'',1,ISNULL(FAdjustPrice,0)
FROM TImpCourse
--WHERE FCourseId 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(),FMemId,FId,0,FCourseId,FTime = getdate(),FPurTimes,0,0,0,
FCompId,
'DR','Import',0,'',0
FROM TImpCourse
SELECT * FROM TMemberCourse
UPDATE TMemberCourse SET FUsedPurTimes = 0 WHERE FUsedPurTimes IS NULL