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

648 lines
19 KiB

1 year ago
SELECT * FROM TIMpMember
SELECT * INTO TImpMember FROM DEMO_MF..TImpMember
SELECT * INTO TImpMemberCourse FROM DEMO_MF..TImpMemberCourse
SELECT * FROM TCompany
SELECT count(*) FROM TImpMember WHERE ID NOT IN(SELECT FCardId FROM TImpMemberAcct)
SELECT * FROM TImpMemberAcct
WHERE 1=1
AND intAccountCate != 1
SELECT * FROM TImpMember WHERE FMobile = '171129061825'
delete TImpError
SELECT * FROM TImpMemberCourse
SELECT *INTO TMember_Exist FROM TMember WHERE FMemNo IN(SELECT CardNo FROM TImpMember)
SELECT * FROM TImpMember WHERE Credit != 0
SELECT * FROM TUser
SELECT * FROM TImpMember WHERE CardNo = '800128'
CREATE TABLE TImpError
(
CardId BIGINT,
Error VARCHAR(7000)
)
ALTER TABLE TImpMember ADD FIsLoad BIT NOT NULL DEFAULT 0
ALTER TABLE TImpMember ADD FCardTypeName VARCHAR(100)
ALTER TABLE TImpMember ADD FMemId BIGINT
ALTER TABLE TImpMember ADD FMemNo VARCHAR(50)
ALTER TABLE TImpMember ADD FCardNo VARCHAR(50)
ALTER TABLE TImpMember ADD FName VARCHAR(50)
ALTER TABLE TImpMember ADD FGender INT
ALTER TABLE TImpMember ADD FCardState 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 FBalance2 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 FCardTypeName = CardName
DROP TABLE TImpCardType
GO
CREATE TABLE TImpCardType
(
FShopId INT ,
FCardTypeName VARCHAR(500),
FCardTypeNo VARCHAR(50),
FCardTypeId BIGINT
)
DELETE TImpCardType
INSERT TImpCardType(FCardTypeId,FCardTypeNo,FCardTypeName)
SELECT dbo.FNNewId(),
'T' + FCardTypeName ,
FCardTypeName AS Name
FROM TImpMember
GROUP BY FCardTypeName
ORDER BY FCardTypeName
SELECT * FROM TImpCardType
SELECT * FROM TImpMember WHERE FCardTypeName IS NULL
delete TMemberCardType WHERE FId > 111
WHERE FId NOT IN(SELECT FCardTypeiD FROM TMemberCardTypeSub)
AND FId > 11
SELECT * FROM TMemberCardType
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 =FCardTypeId, FCardTypeNo,FCardTypeName,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
WHERE FCardTypeNo NOT IN(SELECT FNO FROM TMemberCardType)
ORDER BY FCardTypeName
INSERT INTO TMemberCardTypeSub(FId,FCompId,FCardTypeId,FAllowSale,FAllowRchg,FEnabled)
SELECT dbo.FNNewId(),dbo.FNCompId('001'),I.FCardTypeId,1,1,1
FROM TImpCardType AS I
INSERT INTO TMemberCardTypeSub(FId,FCompId,FCardTypeId,FAllowSale,FAllowRchg,FEnabled)
SELECT dbo.FNNewId(),dbo.FNCompId('001'),I.FCardTypeId,1,1,1
FROM TImpCardType AS I
SELECT CardTypeName FROM TImpMember
WHERE CardTypeName NOT IN(SELECT FCardTypeName FROM TImpCardType)
GROUP BY CardTypeName
SELECT * FROM TImpMember
UPDATE TImpMember SET FMemId = ID
UPDATE TImpMember SET FCardId = CARDId
UPDATE TImpMember SET FMemNo = Code
UPDATE TImpMember SET FCardno = Code
UPDATE TImpMember SET FName = Name
UPDATE TImpMember SET FMobile = Mobile
UPDATE TImpMember SET FGender = CASE WHEN Sex = '0' THEN 1 ELSE '0' END
UPDATE TImpMember SET FBalance = CAST(Amount AS FLOAT)
UPDATE TImpMember SET FBalance2 = CAST(ZSAmount AS FLOAT)
UPDATE TImpMember SET FCreateDate = CreateTime
UPDATE TImpMember SET FExpiredDate = EndTime
UPDATE TImpMember SET FCompId = dbo.FNCompId('001') WHERE groupName = '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD>6<EFBFBD>'
UPDATE TImpMember SET FCompId = dbo.FNCompId('003') WHERE groupName = '<EFBFBD><EFBFBD>ɯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
SELECT * FROM TCompany
UPDATE TImpMember SET FCardState = 1 WHERE States = '<EFBFBD><EFBFBD>Ч'
SELECT * FROM TImpMember WHERE States != '<EFBFBD><EFBFBD>Ч'
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE TImpMember SET FBirthday = NULL
UPDATE TImpMember SET FBirthday = Brithday
UPDATE TImpMember SET FBirthdayType = 'G'
UPDATE TImpMember SET FBirthdayType = 'L' WHERE IsCNBirth = 1
ALTER TABLE TImpMember ADD FBirthdayStr VARCHAR(10)
UPDATE TImpMember SET FBirthdayStr = '' WHERE FBirthdayStr = '9999-02-30'AND FBirthdayType = 'G'
UPDATE TImpMember SET FBirthdayStr = '9996-02-29'
WHERE 1=1
AND FBirthdayStr LIKE '%02-29' OR FBirthdayStr LIKE
AND FBirthdayType = 'L'
SELECT FBirthdayStr FROM TImpMember WHERE FBirthdayStr LIKE '___-__-__'
UPDATE TImpMember SET FBirthdayStr = '9999' + SUBSTRING(FBirthdayStr,4,6) WHERE FBirthdayStr LIKE '___-__-__'
SELECT FBirthdayStr ,FBirthdayType
,CAST(FBirthdayStr AS DATETIME)
FROM TImpMember
WHERE 1=1
AND LEN(FBirthdayStr) = 10
AND FBirthdayStr > '9999-02-28'
AND FBirthdayStr != ''
ORDER BY FBirthdayStr ASC
SELECT FBirthdayStr FROM TImpMember
UPDATE TImpMember SET FBirthday = FBirthdayStr
WHERE LEN(FBirthdayStr) = 10
SELECT Birth FROM TImpMember
WHERE LEN(Birth) = 10
AND Birth NOT LIKE '00%'
SELECT Birth FROM TImpMember
--״̬
UPDATE TMemberCardAccount SET FExpiredDate = null
SELECT * FROM TImpMember WHERE StatusReason NOT IN('<EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<EFBFBD><EFBFBD>ʧ','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
UPDATE TImpMember SET FCardState = 1 WHERE StatusReason = '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
UPDATE TImpMember SET FCardState = 1 WHERE StatusReason = '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
UPDATE TImpMember SET FCardState = 16 WHERE StatusReason = '<EFBFBD><EFBFBD>ʧ'
UPDATE TImpMember SET FCardState = 1 WHERE StatusReason = '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
SELECT FCardnO,fnAME, FMobile,FBalance,StatusReason FROM TImpMember WHERE FCardNo = '6011238'
UPDATE TImpMember SET F
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A SET A.FCardTypeId = B.FCardTypeId
FROM TImpMember AS A,TImpCardType AS B
WHERE A.FCardTypeName = B.FCardTypeName
SELECT FCardTypeName FROM TImpMember
WHERE FCardTypeId IS NULL
GROUP BY FCardTypeName
--<EFBFBD>ظ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SELECT FMemNo,SUM(1) FROM TIMpMEMBER
GROUP BY FMemNo
ORDER BY SUM(1) DESC
SELECT FCardnO,SUM(1) FROM TIMpMEMBER
GROUP BY FCardnO
ORDER BY SUM(1) DESC
SELECT FMemId,SUM(1) FROM TIMpMEMBER
GROUP BY FMemId
ORDER BY SUM(1) DESC
SELECT * FROM TIMpMEMBER WHERE FMemID = 189072
SELECT CardnO,MemberCode FROM TImpMember WHERE FCardNo != FMemNo
AND FCompId = dbo.FNCompId('001')
DELETE TImpCardType
SELECT * FROM TImpMember WHERE MemberID = 189072
SELECT * FROM TImpMember WHERE MemberCode = '00004'
SELECT * FROM TImpMember WHERE Balance > '9'
SELECT * FROM TImpMember
SELECT * FROM TCompany
SELECT ShopName,ShopId,FCompId FROM TImpMember
GROUP BY ShopName,FCompId,ShopId
SELECT * FROM TImpShopInfo
GROUP BY CardTypeId,CardTypeName
UPDATE
SELECT A.CardTypeName,B.FNo,B.FId FROM TImpMember AS A,TMemberCardType AS B
WHERE A.CardTypeName NOT IN(SELECT FCardTypeName FROM TImpCardType)
AND A.CardTypeName = B.FName
GROUP BY A.CardTypeName,B.FNo,B.FId
SELECT * FROM TImpMember
UPDATE TMemberCard SET FExpiredDate = '9000-01-01'
SELECT * FROM TMemberCardType WHERE FName LIKE '%<EFBFBD><EFBFBD><EFBFBD><EFBFBD>%'
SELECT * FROM TUser
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD>
ALTER TABLE TImpMemberCourse ADD FMemId BIGINT
ALTER TABLE TImpMemberCourse ADD FCreateDate DATETIME
ALTER TABLE TImpMemberCourse ADD FExpiredDate DATETIME
ALTER TABLE TImpMemberCourse ADD FItemId BIGINT
ALTER TABLE TImpMemberCourse ADD FCardTypeId BIGINT
ALTER TABLE TImpMemberCourse ADD FCardId BIGINT
ALTER TABLE TImpMemberCourse ADD FCompId BIGINT
ALTER TABLE TImpMemberCourse ADD FMemNo BIGINT
ALTER TABLE TImpMemberCourse ADD FCardTypeName VARCHAR(100)
ALTER TABLE TImpMemberCourse ADD FPurTimes DECIMAL(18,6)
ALTER TABLE TImpMemberCourse ADD FUsedPurTimes DECIMAL(18,6)
//<EFBFBD>Ƴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE TImpMemberCourse SET FCardTypeName = packageName + '.' + shopName
SELECT FCardTypeName FROM TImpMemberCourse
GROUP BY FCardTypeName
UPDATE A
SET A.FMemId = B.FMemId
FROM TImpMemberCourse AS A,TImpMember AS B
WHERE A.Code = B.Code
CREATE TABLE TImpCourse
(
FItemId BIGINT,
FCourseId BIGINT,
FItemNo VARCHAR(100),
FItemName VARCHAR(100)
)
DELETE TImpCourse
INSERT TImpCourse(FItemId,FCourseId,FItemNo,FItemName)
SELECT dbo.FNNewId(),dbo.FNNewId(),FCardTypeName,FCardTypeName
FROM TImpMemberCourse
GROUP BY FCardTypeName
SELECT * FROM TImpMemberCourse
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 FItemId,'T'+FItemName,'T'+FItemName,'T'+FItemName,'T'+FItemName,0,dbo.FNGetFirstPinYin(FItemName),'',1,1,1,'','','',1,0,0,0,0,0,0,0,1
FROM TImpCourse
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 IN( dbo.FNCompId('001'),dbo.FNCompId('002'))
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 FItemId FROM TImpCourse)
INSERT INTO TCourse(FId,FNo,FName,FBriefCode,FItemId,FPackId,FSequence,FTypeId,FTimes,FFreeTimes,FDurable,FValidityPeriodUnit,FValidityPeriod,FCreateDate,FExpiredDate,FDescription,FEnabled,FPrice,FAmount,FCalcMode)
SELECT FCourseId,
'T'+I.FItemName + 'L1',
'T'+I.FItemName ,
'' AS FBriefCode,
I.FItemId AS FItemId,
0 AS FPackId,
1 AS FSequence,
0 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 TImpCourse AS I
SELECT * FROM TImpMemberCourse
UPDATE A
SET A.FCreateDate = CreateTime,
A.FExpiredDate = EndTime
FROM TImpMemberCourse AS A
UPDATE TImpMemberCourse SET FCompId = dbo.FNCompId('001') WHERE groupName = '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD>6<EFBFBD>'
UPDATE TImpMemberCourse SET FCompId = dbo.FNCompId('003') WHERE groupName = '<EFBFBD><EFBFBD>ɯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
UPDATE A
SET A.FCardId = dbo.FNNewId() -- ID <EFBFBD>ײ<EFBFBD>ID<EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>
FROM TImpMemberCourse AS A
WHERE A.FCardId IS NULL
UPDATE A
SET A.FItemId = B.FItemId,
A.FCardTypeId = B.FCourseId
FROM TImpCourse AS B,TImpMemberCourse AS A
WHERE B.FItemName = A.FCardTypeName
UPDATE TImpMemberCourse SET FPurTimes = Num
UPDATE TImpMemberCourse SET FUsedPurTimes = CAST(Num AS FLOAT) - HaveNum
UPDATE A
SET A.FMemId = B.FMemId
FROM TImpMemberCourse AS A,TImpMember AS B
WHERE A.CustomerId = B.ID
ALTER TABLE TImpMemberCourse ADD FIsNew BIT
UPDATE TImpMemberCourse SET FIsNew = 0
UPDATE TImpMemberCourse SET FIsNew = 1 WHERE FMemId IS NULL
UPDATE TImpMemberCourse SET FMemId = 100000 + CustomerId WHERE FIsNew = 1
UPDATE TImpMember SET FMemNO = 'A' + FMemNo,FCardnO = 'A' + FCardNo
WHERE FMemNo IN(SELECT FMemNo FROM TMember)
SELECT FMemNo FROM TImpMember
GROUP BY FMemNo
HAVING(SUM(1)) > 1
UPDATE TImpMember SET FMemNO = 'T' + FMemNO,FCardNo = 'T'+ FCardNo
UPDATE A
SET A.FMemNo = B.FCardNo
FROM TImpMember AS A,(
SELECT Id,MIN(CreateTime) AS CreateTime
FROM TImpMember
GROUP BY ID
HAVING(SUM(1) > 1)) AS C,TImpMember AS B
WHERE A.Id = B.ID
AND A.ID = C.ID
AND B.CreateTime = C.CreateTime
UPDATE TImpMember SET FCompId = 1
UPDATE TImpMember SET FBirthdayType = 'G'
SP_RENAME 'TImpMember.FMemo','Memo'
ALTER TABLE TImpMember ADD FMemo VARCHAR(1000)
UPDATE TImpMember SET FMemo = Memo
UPDATE TImpMember SET FMemo = REMARK + ' ' +Memo
WHERE REMARK not in('<EFBFBD><EFBFBD>ֵ<EFBFBD>ۿ<EFBFBD>','ϵͳ<EFBFBD>')
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,
MIN(FMemNo) AS FMemNo,
FName AS FName,
dbo.FNGetFirstPinYin(FName),
0 AS FTypeId,
FCompId AS FCompId,
MIN(CreateTime) 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,
0 AS FPoint,
1 AS FRecvConsSMS,
1 AS FRecvBulkSMS,
'' AS FMemo,
'<EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5
from TImpMember
GROUP BY FMemId, FName,FCompId,FGender,FBirthdayType, FBirthday ,FMobile
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,
MIN(Code) AS FMemNo,
Name AS FName,
dbo.FNGetFirstPinYin(Name),
0 AS FTypeId,
FCompId AS FCompId,
MIN(CreateTime) AS FCreateDate,
0 AS FGender,
'' AS FBirthdayType,
NULL 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,
'<EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5
from TImpMemberCourse
WHERE FIsNew = 1
GROUP BY FMemId, Name,FCompId,Mobile
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId,
FMemo)
SELECT
FCardId AS FId,
FCardNo AS FNo,
FCardTypeId AS FTypeId,
(SELECT FValueType FROM TMemberCardType WHERE FId = FCardTypeId) AS FValueType,
FCompId AS FCompId,
FMemId AS FMemId,
FCardState AS FState,
FCreateDate AS FCreateDate,
FExpiredDate AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FCompId AS FSaleCompId,
0 AS FSaleBillId,
ISNULL(FMemo,'') AS FMemo
FROM TImpMember
UPDATE TImpMember SET FCardState = 1 WHERE FCardState IS NULL
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,NULL 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,A.FCompId,'DR','Import',0,'',A.FBalance,0,A.FBalance,0,getdate(),'<EFBFBD><EFBFBD>Excel<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD>'
FROM TImpMember AS A
WHERE FCardTypeId IS NOT NULL
INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo)
SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,10,FBalance2,FBalance2,0,FCreateDate,null AS FExpiredDate,''
FROM TImpMember AS A
WHERE FCardTypeId IS NOT NULL
AND FBalance2 != 0
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,10,getdate(),A.FCardTypeId,A.FCompId,'DR','Import',0,'',A.FBalance2,0,A.FBalance2,0,getdate(),'<EFBFBD><EFBFBD>Excel<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD>'
FROM TImpMember AS A
WHERE FCardTypeId IS NOT NULL
AND FBalance2 > 0
DELETE TMemberCardAcctHist WHERE FMemId IN(SELECT FMemId FROM TImpMember)
SELECT FCardId FROM TImpMemberCourse
GROUP BY FCardId
HAVING(SUM(1) > 1)
SELECT * FROM TIMpMemberCourse WHERE FCardId = 894
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,FCardTypeId,0,FItemId,FCompId,FPurTimes,FUsedPurTimes,0,0,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,'ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',1,0
FROM TImpMemberCourse AS A
SELECT REMARK FROM TIMpMember
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(FCardTypeId,0),getdate(),FPurTimes,0,FUsedPurTimes,0,FCompId,'DR','Import',0,'',0,getdate()
FROM TImpMemberCourse AS A
--<EFBFBD><EFBFBD>ʷ
ALTER TABLE TImpMemberTransHist ADD FCompId BIGINT
UPDATE A
SET A.FCompId = B.FCompId
FROM TImpMemberTransHist AS A,TImpMember AS B
WHERE A.CustomerId = B.Id
UPDATE A
SET A.FCompId = B.FCompId
FROM TImpMemberTransHist AS A,TImpMemberCourse AS B
WHERE A.CustomerId = B. CustomerId
INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo)
SELECT dbo.FNNewId(),A.CustomerId,A.Time,0,A.FCompId,'DR','Import',A.OrderId,A.ProName,A.TotalSum,A.ProNum,A.TotalSum,PayType,'',''
FROM TImpMemberTransHist AS A
WHERE A.CustomerId IN(SELECT ID FROM TImpMember)
select count(1) from TImpMemberTransHist
SELECT * FROM TImpMemberTransHist
GROUP BY orderid
HAVING SUM(1) > 1
SELECT count(1) FROM TImpMemberTransHist_
WHERE orderid = '2017032517430475'
sp_rename 'TImpMemberTransHist','TImpMemberTransHist_'
drop table TImpMemberTransHist_
SELECT count(1) FROM TImpMemberCOURSE