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/HairHere/SQLQuery2.sql

321 lines
9.6 KiB

CREATE TABLE TImpCourse
(
FMemNo VARCHAR(100),
FName VARCHAR(100),
FMobile VARCHAR(100),
FCourseName VARCHAR(100),
FTimes DECIMAL(18,6),
FExpiredDate DATETIME
)
SELECT * FROM TImpCourse
DELETE TImpCourse
SELECT * FROM TImpCard
SELECT * FROM TCompany
--初始化
ALTER TABLE TImpCard ADD FMemId BIGINT
ALTER TABLE TImpCard ADD FMemNo VARCHAR(50)
ALTER TABLE TImpCard ADD FName VARCHAR(50)
ALTER TABLE TImpCard ADD FGender INT
ALTER TABLE TImpCard ADD FMobile VARCHAR(50)
ALTER TABLE TImpCard ADD FCreateDate DATETIME
ALTER TABLE TImpCard ADD FExpiredDate DATETIME
ALTER TABLE TImpCard ADD FCompId BIGINT
ALTER TABLE TImpCard ADD FMemo VARCHAR(1000)
ALTER TABLE TImpCard ADD FArrear DECIMAL(18,6)
ALTER TABLE TImpCard ADD FPoint DECIMAL(18,6)
ALTER TABLE TImpCard ADD FBirthday DATETIME
ALTER TABLE TImpCard ADD FBirthdayType CHAR
ALTER TABLE TImpCard ADD FCardNo VARCHAR(50)
ALTER TABLE TImpCard ADD FCardTypeId BIGINT
ALTER TABLE TImpCard ADD FCreateDate DATETIME
ALTER TABLE TImpCard ADD FExpiredDate DATETIME
ALTER TABLE TImpCard ADD FCompId BIGINT
ALTER TABLE TImpCard ADD FMemo VARCHAR(1000)
ALTER TABLE TImpCard ADD FBalance DECIMAL(18,6)
ALTER TABLE TImpCard ADD FMemId BIGINT
ALTER TABLE TImpCard ADD FCardId BIGINT
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)
SELECT IDENTITY(INT,1,1) AS FIndex, AS FName
INTO TImpCardType
FROM TImpCard
WHERE IS NOT NULL
GROUP BY
ALTER TABLE TImpCardType ADD FNo VARCHAR(100)
ALTER TABLE TImpCardType ADD FId BIGINT
UPDATE TImpCardType SET FId =dbo.FNNewId()
UPDATE TImpCardType SET FNo = 'L' + CAST(FIndex AS VARCHAR)
INSERT TMemberCardType(FId,FNo,FName,FValueType,FMaterial,FPrice,FAcctId,FDeposit,FAcctId2,FDeposit2,FAcctId3,FDeposit3,FTimes,FAlertBalance,FMinRchgAmt,FValidityPeriod,FValidityPeriodUnit,FAllowSale,FAllowRchg,FEnabled,FOrder,FSalePointMode,FSalePointValue,FRchgPointMode,FRchgPointValue)
SELECT CardTypeId = FId,
CardTypeId = FNo,
FName AS FName,
1 AS FValueType,
2 AS FMaterial,
0 AS FPrice,
3 AS FAcctId,
0 AS FDeposit,
0 as FAcctId2,
0 AS FDeposit2,
0 AS FAcctId3,
0 AS FDeposit3,
0 AS FTimes,
0 AS FAlertBalance,
0 AS FMinRchgAmt,
0 AS FValidityPeriod,
0 AS FValidityPeriodUnit,
0 AS FAllowSale,
0 AS FAllowRchg,
1,
1,
0 AS FSalePointMode,
0 AS FSalePointValue,
0 AS FRchgPointMode,
0 AS FRchgPointValue
FROM TImpCardType
UPDATE TMemberCardType SET FNo = FNo
SELECT * FROM TUser
UPDATE TMemberCardType SET FAllowRchg = 1 WHERE FNo LIKE 'L%'
UPDATE TImpCOurse SET FMobile = REPLACE(FMobile,'-','')
UPDATE TImpCOurse SET FMobile = REPLACE(FMobile,' ','')
UPDATE TImpCOurse SET FMobile = LEFT(FMobile,11)
DELETE TImpCard WHERE
IS NULL
AND NOT IN (SELECT FName FROM TImpCourse)
AND NOT IN(SELECT FMobile FROM TImpCourse)
SELECT * FROM TImpCard
SELECT * FROM TImpCOurse
SELECT * FROM TCompany
UPDATE TImpCard SET FMemId = dbo.FNNewId()
UPDATE TImpCard SET FCardId = dbo.FNNewId()
UPDATE TImpCard SET FMemNo =
UPDATE TImpCard SET FCardNo =
UPDATE TImpCard SET FName =
UPDATE TImpCard SET FMobile =
UPDATE TImpCard SET FGender = 0
UPDATE TImpCard SET FCreateDate = '2016-01-01'
UPDATE TImpCard SET FExpiredDate = '9999-01-01'
UPDATE TImpCard SET FCompId = 4922467653992830642
UPDATE TImpCard SET FBalance =
UPDATE A
SET A.FCardTypeId = B.FId
FROM TImpCard AS A,TImpCardType AS B
WHERE A. = B.FName
UPDATE TImpCard SET FArrear = 0
UPDATE TImpCard SET FMemo = ''
UPDATE TImpCard SET FPoint = 0
UPDATE TImpCard SET FBirthdayType = 'G'
SELECT * FROM TImpCourse WHERE FCOurseid is null
UPDATE TImpCard SET FMemNo = FMobile,FCardNo = FMobile WHERE FMobile = 13793248960
UPDATE TImpCourse SET FMemNo = FMobile WHERE FMobile = 13793248960
SELECT FCourseName FROM TImpCourse
GROUP BY FCourseName
UPDATE A
SET A.FCourseId = B.FId,
A.FItemId = B.FItemId
FROM TImpCourse AS A,TCOurse AS B
WHERE A.FCourseName = B.FName
UPDATE TImpCourse SET FMemNO = REPLACE(FmemNo ,' ','')
UPDATE A
SET A.FMemId =B.FMemId
FROM TImpCourse AS A,TImpCard AS B
WHERE A.FMemNO = B.FMemNo
UPDATE TImpCourse SET FId = dbo.FNNewId()
UPDATE TImpCourse SET FPurTimes = FTimes
UPDATE TImpCourse SET FUsedPurTimes = 0
UPDATE TImpCourse SET FCreateDate = '2000-01-01'
UPDATE TImpCourse SET FCompId = 4922467653992830642
SELECT * FROM TImpCourse WHERE FMemId IS NULL
SELECT * FROM TImpCard WHERE FMobile = '13605423309'
----------
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,
'啊哈软导入' AS FMemo,
'' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5
from TImpCard
WHERE FMemNO IN (SELECT FMemNo FROM TMember)
SELECT FMemNO FROM TImpCard GROUP BY FMemNO HAVING(COUNT(1)) > 1
SELECT * FROM TImpCard WHERE FMemNo = '13793248960'
WHERE FMemNo NOT IN (SELECT FMemNo FROM TImpMember GROUP BY FMemNo HAVING(COUNT(1) > 1))
SELECT FMemNo,SUM(1) FROM TImpMember GROUP BY FMemNo HAVING(COUNT(1) > 1)
--可导卡
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,
ISNULL(FCreateDate,1900) AS FCreateDate,
DATEADD(year,100, ISNULL(FCreateDate,2000)) AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FCompId AS FSaleCompId,
0 AS FSaleBillId,
'啊哈软导入' AS FMemo
FROM TImpCard
WHERE FCardNo NOT IN (SELECT FMemNo FROM TImpMember GROUP BY FMemNo HAVING(COUNT(1) > 1))
AND FMemId 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 TImpCard AS A
WHERE FCardId IN(SELECT FCardId FROM TMemberCard)
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,'',A.FBalance,0,A.FBalance,0,getdate(),'从老系统导入'
FROM TImpCard AS A
WHERE FCardId IN(SELECT FCardId FROM TMemberCard)
SELECT * FROM TImpCourse WHERE FMemId NOT IN(SELECT FMemId FROM TImpCard)
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,FCreateDate,FExpiredDate,'DR.Import',0,0,0,'啊哈软导入',1,ISNULL(FAdjustPrice,0)
FROM TImpCourse
WHERE FCourseId IS NOT NULL
AND FMemId IS NOT NULL
UPDATE TIMpCourse SET FMemId = 6617034505766672330 WHERE FMobile = '13793248960'
INSERT INTO TMemberCourseHist(FId,FMemId,FMemCourseId,FPackId,FCourseId,FTime,FPurTimes,FFreeTimes,FUsePurTimes,FUseFreeTimes,
FPurAmount,FFreeAmount,FUsePurAmount,FUseFreeAmount,FCompId,
FBillType,FBizType,FTransId,FTransNo,FTransDetailId)
SELECT dbo.FNNewId(),FMemId,FId,0,FCourseId,FTime = getdate(),FPurTimes,FUsedPurTimes,0,0,
ISNULL(FPurAmount,0),0,0,0,1,
'DR','Import',0,'',0
FROM TImpCourse
WHERE FCourseId IS NOT NULL
AND FMemId IS NOT NULL