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

636 lines
21 KiB

use HuHeHaoTe_ShengLanDi
SELECT * FROM TImpMember
ALTER TABLE TImpMember ADD MemId VARCHAR(50)
ALTER TABLE TImpMember ADD Birthday VARCHAR(100)
ALTER TABLE TImpMember ADD Sex VARCHAR(100)
UPDATE A
SET A.MemId = B.Id,
A.Sex = B.Sex
FROM TImpMember AS A,TImpMemberInfo AS B
WHERE A.Phone = B.Phone
ALTER TABLE TImpMemberInfo ADD FMemId BIGINT
ALTER TABLE TImpMemberInfo ADD FCompId BIGINT
ALTER TABLE TImpMemberInfo ADD FMemNo VARCHAR(50)
ALTER TABLE TImpMemberInfo ADD FGender INT
ALTER TABLE TImpMemberInfo ADD FMobile VARCHAR(50)
ALTER TABLE TImpMemberInfo ADD FName VARCHAR(50)
ALTER TABLE TImpMemberInfo ADD FBirthdayType VARCHAR(50)
ALTER TABLE TImpMemberInfo ADD FBirthday DATETIME
ALTER TABLE TImpMemberInfo ADD FCreateDate DATETIME
--»áÔ±
ALTER TABLE TImpMember ADD FMemId BIGINT
ALTER TABLE TImpMember ADD FCardId BIGINT
ALTER TABLE TImpMember ADD FCardTypeName VARCHAR(100)
ALTER TABLE TImpMember ADD FCardNo VARCHAR(50)
ALTER TABLE TImpMember ADD FCompId BIGINT
ALTER TABLE TImpMember ADD FCardTypeId BIGINT
ALTER TABLE TImpMember ADD FMemo VARCHAR(MAX)
ALTER TABLE TImpMember ADD FBalance DECIMAL(18,6)
ALTER TABLE TImpMember ADD FBalance2 DECIMAL(18,6)
ALTER TABLE TImpMember ADD FPoint DECIMAL(18,6)
ALTER TABLE TImpMember ADD FCreateDate DATETIME
ALTER TABLE TImpMember ADD FExpiredDate DATETIME
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 =dbo.FNNewId(), '[¾ü×ÓÀÏ¿¨]'+CardCategoryName, '[¾ü×ÓÀÏ¿¨]'+CardCategoryName as name,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 TImpMember
group BY CardCategoryName
SELECT * FROM TImpMember WHERE FCardNo =''
SELECT * FROM TImpMemberInfo WHERE CardId = 'cbcc3a17-5078-4cf8-9bcd-ac970120a5a1'
SELECT * FROM TImpMemberInfo WHERE Phone = '13614848243'
SELECT * FROM TImpMember WHERE Phone = '13614848243'
--´¦Àí¿¨ºÅ
UPDATE TImpMember SET FCardNo = cardCode
--ûÓп¨ºÅµÄ¸üгÉÊÖ»úºÅ
UPDATE A
SET A.FCardNo = B.Phone
FROM TImpMember AS A,TImPMemberInfo AS B
WHERE (( A.Phone = B.Phone AND A.Phone != '') or A.MemberCardId = B.CardId)
AND ISNULL(A.FCardNo,'') = ''
--ûÓÐÊÖ»úºÅµÄ¸üгÉÐÕÃû
UPDATE A
SET A.FCardNo = B.Name
FROM TImpMember AS A,TImPMemberInfo AS B
WHERE (( A.Phone = B.Phone AND A.Phone != '') or A.MemberCardId = B.CardId)
AND ISNULL(A.FCardNo,'') = ''
--´¦ÀíÖظ´¿¨ºÅ
DROP TABLE #Card
SELECT FCardNo into #Card
FROM TImpMember
GROUP BY FCardNo
HAVING(SUM(1)) > 1
ALTER TABLE TImpMember ADD FSeq INT IDENTITY
ALTER TABLE TImpMember ADD FIndex INT
UPDATE A
SET A.FIndex = 1+(SELECT COUNT(1) FROM TImpMember AS B WHERE A.FCardNo = B.FCardNo AND (A.FCreateDate > B.FCreateDate OR (A.FCreateDate = B.FCreateDate AND (A.FSeq > B.FSeq) )))
FROM TImpMember AS A
UPDATE TImpMember SET FCardNo = FCardNo + '.' + CAST(FIndex AS VARCHAR)
WHERE FCardNo IN( SELECT FCardNo FROM #Card)
UPDATE TImpMemberInfo SET FMemId = dbo.FNNewId() WHERE FMemId IS NULL
UPDATE TImpMemberInfo SET FName = Name
UPDATE TImpMemberInfo SET FMobile = Phone
UPDATE TImpMemberInfo SET FGender = CASE WHEN sex = 'ÄÐ' THEN 1 ELSE 0 END
UPDATE TImpMemberInfo SET FCompId = dbo.FNCompId('001')
UPDATE TImpMemberInfo SET FMemId = dbo.FNNewId()
UPDATE TImpMemberInfo SET FBirthday = null,FBirthdayType = 'G'
UPDATE TImpMemberInfo SET FMemNo = NULL
UPDATE A
SET A.FMemNo = b.FCardNo,
A.FCreateDate = B.addDate
FROM TImpMemberInfo AS A,TImpMember AS B
WHERE (( A.Phone = B.Phone AND A.Phone != '') or B.MemberCardId = A.CardId)
AND A.CardId != '00000000-0000-0000-0000-000000000000'
UPDATE TImpMemberInfo SET FMemNo = Phone WHERE FMemNo IS NULL
AND CardId != '00000000-0000-0000-0000-000000000000'
UPDATE TImpMember SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL
SELECT * FROM TImpMemberInfo
WHERE CardId NOT IN(SELECT MemberCardId FROM TImpMember)
UPDATE A
SET A.FMemId = B.FMemId
FROM TImpMember AS A,TImpMemberInfo AS B
WHERE A.Phone = B.Phone
UPDATE TImpMember SET FCompId = dbo.FNCompId('001')
UPDATE TImpMember SET FMemo = ISNULL(CardRemark,'')
UPDATE TImpMember SET FMemo = '' WHERE FMemo IS NULL
UPDATE TImpMember SET FPoint = 0
UPDATE TImpMember SET FBalance = FactBalances
UPDATE TImpMember SET FBalance2 = DonateBalances
UPDATE TImpMember SET FCreateDate = addDate
UPDATE TImpMember SET FExpiredDate = expiryDate WHERE expiryDate != ''
UPDATE TImpMember SET FExpiredDate = dateadd(year,100,FCreateDate) where FExpiredDate IS NULL
UPDATE A
SET A.FCardTypeId = B.FId
FROM TImpMember AS A,TMemberCardType AS B
WHERE '[¾ü×ÓÀÏ¿¨]' + A.CardCategoryName = B.FName
SELECT * FROM TImpMember WHERE FExpiredDate IS NULL
UPDATE TImpMember SET FBirthdayType = 'G'
SELECT * FROM TImpMemberInfo WHERE FMemNo IN(SELECT FMemNo FROM TMember)
UPDATE TImpMemberInfo SET FMemNo = 'JZ' + FMemNo WHERE FMemNo IN(SELECT FMemNo FROM TMember UNION ALL SELECT FCardNo FROM TMemberCard)
UPDATE TImpMember SET FCardNo = 'JZ' + FCardNo WHERE FCardNo IN(SELECT FMemNo FROM TMember UNION ALL SELECT FCardNo FROM TMemberCard)
SELECT FMemNo FROM TImpMemberInfo
WHERE CardId != '00000000-0000-0000-0000-000000000000'
GROUP BY FMemNo
HAVING SUM(1) > 1
SELECT * FROM TImpMemberInfo WHERE FMemNo = '555555.8'
SELECT * FROM TImpMemberInfo WHERE Phone NOT IN(SELECT Phone FROM TImpMember)
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,
FCreateDate 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,
'' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5
from TImpMemberInfo
WHERE CardId != '00000000-0000-0000-0000-000000000000'
SELECT *FROM TImpMemberInfo WHERE FMemNo = '13947194939'
SELECT FMemNo ,SUM(1)
FROM TImpMemberInfo
WHERE Phone IN(SELECT Phone FROM TImpMember)
GROUP BY FMemNo
HAVING SUM(1) >1
UPDATE TImpMember SET FMemNo = FMemNo + '_1' WHERE MemberCardId = '56bd01da-2739-4fab-b963-aae600b6713b'
UPDATE TImpMember SET FMemNo = FMemNo + '_2' WHERE MemberCardId = '87d8c134-9896-4a97-827b-ab7800ac4a61'
UPDATE TImpMember SET FCompId = dbo.FNCompId('001')
--Ç·¿î
--ÕË»§Ç·¿î
INSERT TMemberArrear(FId,FMemId,FTime,FCompId,FContentType,FCardId,FBillType,FBizType,FTransId,FTransNo,FTransDetailId,FContentId,FArrear,FEmpId,FRepaid,FAcctArrear)
SELECT dbo.FNNewId(),A.FMemId,getdate(),A.FCompId,'Account',A.FCardId,'DR_KK','DR_CardSale',0,'',0,3,A.FArrear,0,0,A.FArrear
FROM TImpMember AS A
WHERE A.FArrear > 0
UPDATE A
SET A.FBalance = B.FBalance - B.FArrear,
A.FArrear = B.FArrear
FROM TMemberCardAccount AS A,TImpMember AS B
WHERE A.FCardId = B.FCardId
AND A.FAcctId = 3
AND B.FArrear > 0
UPDATE A
SET A.FBalance = B.FBalance - B.FArrear,
A.FInAmount = B.FBalance - B.FArrear,
A.FArrear = B.FArrear
FROM TMemberCardAcctHist AS A,TImpMember AS B
WHERE A.FCardId = B.FCardId
AND A.FAcctId = 3
AND A.FBillType = 'DR'
AND B.FArrear > 0
UPDATE A
SET A.FMemId = B.FMemId
FROM TImpMember AS A,TImpMemberInfo AS B
WHERE A.MemberCardId = B.CardId
UPDATE A
SET A.FMemId = B.FMemId
FROM TImpMember AS A,TImpMemberInfo AS B
WHERE A.MemberName = B.Name
AND A.Phone = B.Phone
AND ISNULL(A.FMemId,0) NOT IN(SELECT FMemId FROM TImpMemberInfo)
select * from TImpMember where FMemId is null
SELECT * FROM TImpMemberInfo where phone = '13280028363'
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,
1 AS FState,
FCreateDate AS FCreateDate,
FExpiredDate AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FCompId AS FSaleCompId,
0 AS FSaleBillId,
FMemo AS FMemo
FROM TImpMember
SELECT *FROM TImpMember WHERE FMemId IS 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
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 TImpMember AS A
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
WHERE 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(),'´ÓÀÏϵͳÖе¼Èë'
FROM TImpMember AS A
WHERE FBalance2 > 0
select * from TImpMember WHERE MemberCardId = '198f3da4-99b5-4684-b5e8-aebe01549f37'
select * from TImpMemberInfo WHERE id = '198f3da4-99b5-4684-b5e8-aebe01549f37'
--ÁƳÌ
SELECT * FROM TImpMemberCourse
SELECT TimeName FROM TImpMemberCourse
GROUP BY poolName
select dbo.FNNewId() AS FItemId, ItemName AS FItemName
INTO TImpItem
from TImpMemberCourse
GROUP BY ItemName
sele
select dbo.FNNewId() AS FCourseId, TimeName AS FCourseName,ItemName AS FItemName,CAST(0 AS BIGINT) AS FItemId
INTO TImpCourse
from TImpMemberCourse
GROUP BY TimeName,ItemName
INSERT TImpCourse(FCourseId,FCourseName,FItemId,FItemName)
SELECT dbo.FNNewId(),CouponName,0,CouponName
FROM TImpMemberCoupon
WHERE CouponName NOT IN(SELECT FCourseName FROM TImpCourse)
GROUP BY CouponName
UPDATE A
SET A.FItemId = B.FItemId
FROM TImpCourse AS A,TImpItem AS B
WHERE A.FItemName = B.FItemName
SELECT * FROM TImpCourse
SELECT * FROM TItem
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,FItemName,FItemName,FItemName,FItemName,0,dbo.FNGetFirstPinYin(FItemName),'''',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 FCourseId AS FId,
I.FCourseName,
I.FCourseName,
'' AS FBriefCode,
I.FItemId 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 TImpCourse AS I
ALTER TABLE TImpMemberCourse ADD FMemId BIGINT
ALTER TABLE TImpMemberCourse ADD FId BIGINT
ALTER TABLE TImpMemberCourse ADD FCourseId BIGINT
ALTER TABLE TImpMemberCourse ADD FRemainTimes DECIMAL(18,6)
ALTER TABLE TImpMemberCourse ADD FUsedPurTimes DECIMAL(18,6)
ALTER TABLE TImpMemberCourse ADD FPurAmount DECIMAL(18,6)
ALTER TABLE TImpMemberCourse ADD FCompId BIGINT
ALTER TABLE TImpMemberCourse ADD FItemId BIGINT
ALTER TABLE TImpMemberCourse ADD FCreateDate DATETIME
ALTER TABLE TImpMemberCourse ADD FExpiredDate DATETIME
ALTER TABLE TImpMemberCourse ADD FPurTimes DECIMAL(18,6)
ALTER TABLE TImpMemberCourse ADD FAdjustPrice DECIMAL(18,6)
ALTER TABLE TImpMemberCourse ADD FCalcMode INT
UPDATE A
SET A.FItemId = B.FItemId,
A.FCourseId = B.FCourseId
FROM TImpMemberCourse AS A,TImpCourse AS B
WHERE A.TimeName = B.FCourseName
--»áÔ±ID
<a class="btn btn-info btn-xs" data-backdrop="static" data-target="#publicmodal-lg" data-toggle="modal" href="/MemberCard/TimeAccountLogs?timeAccountDetailId=627da7cd-0ece-49d3-ab4a-abd000eb0be9"><i class="fa fa-edit"></i> ±ä¸üÃ÷ϸ</a> <a class="btn btn-danger btn-xs" data-backdrop="static" data-target="#publicmodal" data-toggle="modal" href="/TimeAccountBackBill/BackCard/627da7cd-0ece-49d3-ab4a-abd000eb0be9?isItem=True"><i class="fa fa-trash"></i> ÍËÏîÄ¿</a><a class="btn btn-success btn-xs" data-backdrop="static" data-target="#publicmodal" data-toggle="modal" href="/Postpone/TimePostpone/e9d40113-fb18-485e-9203-abd000eb0be9" style="margin-left:3px;"><i class="fa fa-edit"></i> ´Î¿¨ÑÓÆÚ</a>
ALTER TABLE TImpMemberCourseEx ADD TimeId VARCHAR(100)
UPDATE TImpMemberCourseEx SET TimeId = SUBSTRING(Operation,CHARINDEX('timeAccountDetailId=',Operation) + LEN('timeAccountDetailId='), 36)
UPDATE A
SET A.FMemId = B.FMemId
FROM TImpMemberCourse AS A,TImpMember AS B,TImpMemberCourseEx AS C
WHERE A.TimeId = C.TimeId
AND C.MemberCardId = B.MemberCardId
UPDATE TImpMemberCourse SET FCalcMode = 1
UPDATE TImpMemberCourse SET FCalcMode = 2 WHERE SurplusAmountDes = '²»ÏÞ'
UPDATE TImpMemberCourse SET FPurTimes = TotalAmount ,FRemainTimes = SurplusAmount WHERE FCalcMode = 1
UPDATE TImpMemberCourse
SET FPurAmount = (CAST(SurplusMoney AS FLOAT) / CAST(SurplusAmount AS FLOAT)) * CAST(TotalAmount AS FLOAt)
WHERE CAST(SurplusAmount AS FLOAT) > 0.0
AND FCalcMode = 1
UPDATE TImpMemberCourse SET FAdjustPrice = FPurAmount / FPurTimes
UPDATE A
SET A.FAdjustPrice = B.FPrice
FROM TImpMemberCourse AS A,TItem AS B
WHERE A.FItemId = B.FId
UPDATE TImpMemberCourse SET FPurTimes = 0,FRemainTimes = 0,FPurAmount = 0 WHERE FCalcMode = 2
UPDATE TImpMemberCourse SET FId = dbo.FNNewId(),FCompId = dbo.FNCompId('001')
UPDATE TImpMemberCourse SET FCreateDate = TimeAddDateStr
UPDATE TImpMemberCourse SET FExpiredDate = TimeExpiryDateStr where TimeExpiryDateStr != ''
UPDATE TImpMemberCourse SET FExpiredDate = NULL
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,FPurTimes - FRemainTimes,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,'´ÓÀÏϵͳµ¼Èë',FCalcMode,ISNULL(FAdjustPrice,0)
FROM TImpMemberCourse
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,FPurTimes - FRemainTimes,0,0,
FCompId,
'DR','Import',0,'',0
FROM TImpMemberCourse
--coupon
SELECT * FROM TImpMemberCoupon
ALTER TABLE TImpMemberCoupon ADD FMemId BIGINT
ALTER TABLE TImpMemberCoupon ADD FId BIGINT
ALTER TABLE TImpMemberCoupon ADD FCourseId BIGINT
ALTER TABLE TImpMemberCoupon ADD FRemainTimes DECIMAL(18,6)
ALTER TABLE TImpMemberCoupon ADD FUsedPurTimes DECIMAL(18,6)
ALTER TABLE TImpMemberCoupon ADD FPurAmount DECIMAL(18,6)
ALTER TABLE TImpMemberCoupon ADD FCompId BIGINT
ALTER TABLE TImpMemberCoupon ADD FItemId BIGINT
ALTER TABLE TImpMemberCoupon ADD FCreateDate DATETIME
ALTER TABLE TImpMemberCoupon ADD FExpiredDate DATETIME
ALTER TABLE TImpMemberCoupon ADD FPurTimes DECIMAL(18,6)
ALTER TABLE TImpMemberCoupon ADD FAdjustPrice DECIMAL(18,6)
ALTER TABLE TImpMemberCoupon ADD FCalcMode INT
UPDATE A
SET A.FItemId = B.FItemId,
A.FCourseId = B.FCourseId
FROM TImpMemberCoupon AS A,TImpCourse AS B
WHERE A.CouponName = B.FCourseName
--»áÔ±ID
UPDATE A
SET A.FMemId = B.FMemId
FROM TImpMemberCoupon AS A,TImpMember AS B
WHERE A.MemberCardId = B.MemberCardId
UPDATE TImpMemberCoupon SET FCalcMode = 1
UPDATE TImpMemberCoupon SET FPurTimes = SurplusAmount ,FRemainTimes = SurplusAmount
UPDATE TImpMemberCoupon
SET FPurAmount = 0
UPDATE TImpMemberCoupon SET FAdjustPrice = FPurAmount / FPurTimes
UPDATE A
SET A.FAdjustPrice = B.FPrice
FROM TImpMemberCoupon AS A,TItem AS B
WHERE A.FItemId = B.FId
UPDATE TImpMemberCoupon SET FId = dbo.FNNewId(),FCompId = dbo.FNCompId('001')
UPDATE TImpMemberCoupon SET FCreateDate = AddDate
UPDATE TImpMemberCoupon SET FExpiredDate = NULL
UPDATE TImpMemberCoupon SET FExpiredDate = NULL
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,0,0,FPurTimes,0,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,'´ÓÀÏϵͳµ¼Èë',FCalcMode,ISNULL(FAdjustPrice,0)
FROM TImpMemberCoupon
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(),0,0,FPurTimes,0,
FCompId,
'DR','Import',0,'',0
FROM TImpMemberCoupon
INSERT TMemberPointHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransId,FTransNo,FInAmount,FOutAmount,FBalance,FMemo,FRecordTime)
SELECT dbo.FNNewId(),A.FMemId,getdate(),0,1,'DR','Import',0,'',FPoint,0,FPoint,'',getdate()
FROM TImpMember AS A WHERE FPoint != 0
ALTER TABLE TImpMemberTransHist ADD FCompId BIGINT
ALTER TABLE TImpMemberTransHist ADD FMemId BIGINT
UPDATE A
SET A.FMemId = B.FMemId,
A.FCompId = B.FCompId
FROM TImpMemberTransHist AS A,TImpMemberInfo AS B
WHERE A.MemId= B.id
select * from TImpMemberTransHist
INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo)
SELECT DBO.FNNewId(),A.FMemId,A.BillDate,0,A.FCompId,'DR','Import',BillCode,ItemName,DiscountMoney,1,DiscountMoney,'',isnull(EmpNames,''),''
FROM TImpMemberTransHist AS A
UPDATE A
SET A.FAdjustPrice = B.FAdjustPrice
FROM TImpMemberCourse AS B,TMemberCourse AS A
WHERE A.FId = B.FId
SELECT COUNT(1) FROM TImpMemberInfo WITH(NOLOCK)
WHERE Id NOT IN(SELECT MemId FROM TImpMemberTransHist WITH(NOLOCK))
SELECT * FROM TMemberCardOldAcctHist
SELECT * FROM TImpMemberAcctHist
ALTER TABLE TImpMemberAcctHist ADD FCompId BIGINT
ALTER TABLE TImpMemberAcctHist ADD FMemId BIGINT
ALTER TABLE TImpMemberAcctHist ADD FCardId BIGINT
UPDATE A
SET A.FMemId = B.FMemId,
A.FCompId = B.FCompId,
A.FCardId = B.FCardId
FROM TImpMemberAcctHist AS A,TImpMember AS B
WHERE A.MemId= B.MemId
select * from TImpMember
select * from TImpMemberAcctHist
INSERT TMemberCardOldAcctHist(FId,FMemId,FCardId,FAcctId,FTime,FCardTypeId,FCompId,FBizType,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo)
SELECT dbo.FNNewId(),FMemId,FCardId,0,BillDate,0,FCompId,MoneyAccountType + '[' + OperateType + ']',BillCode,CASE WHEN CAST(Money AS FLOAT)>0 THEN CAST(MONEY AS FLOAT)ELSE 0 END,
CASE WHEN CAST(Money AS FLOAT) <0 THEN -CAST(MONEY AS FLOAT) ELSE 0 END,AfterBalance,0,getdate(),''
FROM TImpMemberAcctHist
WHERE FMemId IS NOT NULL