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

669 lines
21 KiB

use WuHan_MuXiang
SELECT * FROM TImpCompany
SELECT * FROM TCompany
--Ãŵê
ALTER TABLE TImpCompany ADD FCompId BIGINT
UPDATE A SET A.FCompId = B.FId
FROM TImpCompany AS A,TCompany AS B
WHERE A.name = '¿¨ä¿Æßµê'
AND B.FAbbr = '¿¨ä¿Æßµê'
--씀exec sp_rename 'TImpItem','TImpItemSub'
SELECT id,code,name,reportCatId,mprice,lprice into TImpItem
FROM TImpItemSub
GROUP BY id,code,name,reportCatId,mprice,lprice
ALTER TABLE TImpItem ADD FId BIGINT
ALTER TABLE TImpItem ADD FTypeId BIGINT
UPDATE TImpItem SET FId = dbo.FNNewId()
UPDATE TImpItem SET FTypeId = 4626337264431628995 WHERE reportCatId = 'd28c2f89d6684ffa8efed288e4866149'
UPDATE TImpItem SET FTypeId = 4626337264431628995 WHERE reportCatId = '502fedff34ad4d1585578afee8c881b4'
SELECT * FROM TImpItem
SELECT * FROM TImpBaseType
SELECT * FROM TBasicType WHERE FKey = 'ItemType'
ALTER TABLE TImpBaseType ADD FId BIGINT
UPDATE TImpBaseType SET FId =dbo.FNNewId()
INSERT INTO TBasicType(FId,FKey,FNo,FName,FParentId,FDescription,FImage,FCustom,FOrder,FAllowEdit,FEnabled)
SELECT FId,'ItemType',name,name,0,'','','',0,-1,1
FROM TImpBaseType
update a
set a.ftypeid = b.fid
from TImpItem AS A,TImpBaseType AS B
WHERE A.reportCatId = B.id
ALTER TABLE TImpItemSub ADD FItemId BIGINT
UPDATE A
SET A.FItemId = B.FId
FROM TImpItemSub AS A,TImpItem AS B
WHERE A.id = b.id
INSERT TItem(FId,FNo,FNoOfPad,FName,FAbbr,FTypeId,FBriefCode,FDescription,FPriceMode,FIsService,FStatTimes,FCustom1,FCustom2,FCustom3,FEnabled,FPrice,FVipPrice,FTime,FDctId,FDisplayTypeId,FPointMode,FPointValue,FDeptId,FAllowBooking,FDisplay)
SELECT FId,code,code,name,name,FTypeId,FBriefCode = dbo.FNGetFirstPinYin(name),
FDescription = '',FPriceMode = 0,FIsService = 1,FStatTimes = 1,FCustom1 = '',FCustom2 = '',
FCustom3 = '',FEnabled = 1,lprice ,FVipPrice = mprice ,FTime = 0,FDctId = 0 ,FDisplayTypeId = 0,
FPointMode = 0,FPointValue = 0,FDeptId = 0,FAllowBooking = 1,FDisplay = 1
FROM TImpItem
--¿¨Àà±ð
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 C.FNo = '000'
AND NOT EXISTS(SELECT TOP 1 1 FROM TItemSub AS B WHERE B.FCompId = C.FId AND B.FItemId = I.FId)
INSERT TItemSub(FId,FCompId,FItemId,FPrice,FVipPrice,FTime,FDctId,FPointMode,FPointValue,FDeptId,FAllowBooking,FEnabled)
SELECT dbo.FNNewId(),C.FCompId,I.FId,I.FPrice,I.FVipPrice,I.FTime,I.FDctId,I.FPointMode,I.FPointValue,I.FDeptId,I.FAllowBooking,I.FEnabled
from TItem AS I,TImpItemSub AS B,TImpCompany AS C
WHERE I.FId= B.FItemId
AND C.FCompId > 1
AND C.id = B.compId
--¿¨Àà±ð
exec sp_rename 'TImpCardType','TImpCardTypeSub'
SELECT id,code,name
INTO TImpCardType
FROM TImpCardTypeSub
GROUP BY id,code,name
ALTER TABLE TImpCardType ADD FId BIGINT
UPDATE TImpCardType SET FId = dbo.FNNewId() WHERE FiD IS NULL
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, code,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 TImpCardType
INSERT INTO TMemberCardTypeSub(FId,FCompId,FCardTypeId,FAllowSale,FAllowRchg,FEnabled)
SELECT dbo.FNNewId(),1,I.FId,1,1,1
FROM TImpCardType AS I
INSERT INTO TMemberCardTypeSub(FId,FCompId,FCardTypeId,FAllowSale,FAllowRchg,FEnabled)
SELECT dbo.FNNewId(),C.FCompId,I.FId,1,1,1
FROM TImpCardType AS I,TImpCardTypeSub AS B,TImpCompany AS C
WHERE I.id = B.id
AND b.compId = C.id
AND C.FCompId > 1
--»áÔ±
SELECT * FROM TImpMemberCourse WHERE MemId = '5a350f84c9e77c0007a24d4a'
SELECT * FROM TImpBaseType
use XiAn_ChaoYeDao
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 FMemId = dbo.FNNewId() WHERE FMemId IS NULL
UPDATE TImpMember SET FName = realName
UPDATE TImpMember SET FMobile = mobile
UPDATE TImpMember SET FGender = CASE WHEN gender = 1 THEN 1 ELSE 0 END
UPDATE TImpMember SET FCreateDate = createDate
UPDATE TImpMember SET FBirthday = NULL
UPDATE TImpMember SET FBirthday = Birthday WHERE Birthday!='1900-01-01'
UPDATE TImpMember SET FBirthdayType = 'G'
UPDATE TImpMember SET FCompId = dbo.FNCompId('001')
UPDATE A
SET A.FCompId = B.FCompId
FROM TImpMember AS A,TImpCompany AS B
WHERE A.compId = b.id
UPDATE A
SET A.FMemNo = B.cardNo
FROM TImpMemberCard AS B,TImpMember AS A
WHERE A.id = B.memId
SELECT * FROM TImpMember WHERE FMemNo IS NULL
UPDATE TImpMember SET FIsLoad = 0 WHERE
FMemNo IS NULL
ALTER TABLE TImpMemberCard ADD FCardTypeId BIGINT
ALTER TABLE TImpMemberCard ADD FCourseId BIGINT
ALTER TABLE TImpMemberCard ADD FBalance DECIMAL(18,6)
ALTER TABLE TImpMemberCard ADD FBalance2 DECIMAL(18,6)
ALTER TABLE TImpMemberCard ADD FRemainTimes INT
ALTER TABLE TImpMemberCard ADD FPurTimes INT
ALTER TABLE TImpMemberCard ADD FPurAmount DECIMAL(18,6)
ALTER TABLE TImpMemberCard ADD FItemId BIGINT
ALTER TABLE TImpMemberCard ADD FCreateDate DATETIME
ALTER TABLE TImpMemberCard ADD FExpiredDate DATETIME
ALTER TABLE TImpMemberCard ADD FCardNo VARCHAR(1000)
ALTER TABLE TImpMemberCard ADD FCompId BIGINT
ALTER TABLE TImpMemberCard ADD FCardId BIGINT
ALTER TABLE TImpMemberCard ADD FMemId BIGINT
ALTER TABLE TImpMemberCard ADD FMemo VARCHAR(1000)
ALTER TABLE TImpMemberCard ADD FArrear DECIMAL(18,6)
ALTER TABLE TImpMemberCard ADD FState INT
--ÒÑ¿¨Îª×¼
ALTER TABLE TImpMemberCard ADD FName VARCHAR(50)
ALTER TABLE TImpMemberCard ADD FGender INT
ALTER TABLE TImpMemberCard ADD FMobile VARCHAR(50)
ALTER TABLE TImpMemberCard ADD FBirthday DATETIME
ALTER TABLE TImpMemberCard ADD FBirthdayType CHAR
SELECT b.fcardno,a.realName,b.holderName FROM TImpMemberCard AS B,TImpMember AS A
WHERE A.realName != B.holderName
AND a.id = B.memId
UPDATE A
SET A.FName = A.holderName,
A.FMobile = B.FMobile,
A.FBirthdayType = 'G',
A.FBirthday = b.FBirthday,
A.FGender = B.FGender
FROM TImpMemberCard AS A,TImpMember AS B
WHERE A.memId = b.id
SELECT * FROM TImpMember
SELECT * FROM TImpMemberCard WHERE FMobile = '17633496668'
--¿¨Àà±ð
UPDATE A
SET A.FCardTypeId = B.FId
FROM TImpMemberCard AS A,TImpCardType AS B
WHERE A.typeId = B.id
commit tran
--»áÔ±ID
UPDATE A
SET A.FMemId = B.FMemId
FROM TImpMemberCard AS A,TImpMember AS B
WHERE A.memId = B.id
--ÒÔ¿¨Îª×¼
UPDATE TImpMemberCard SET FMemId = dbo.FNNewId()
UPDATE TImpMemberCard SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL
UPDATE TImpMemberCard SET FCardNO = CardNo
UPDATE TImpMemberCard SET FCompId = dbo.FNCompId('001')
UPDATE TImpMemberCard SET FCreateDate = activeDate
UPDATE TImpMemberCard SET FExpiredDate = ExpireDate
UPDATE TImpMemberCard SET FMemo = remark
UPDATE TImpMemberCard SET FBalance = balance
UPDATE TImpMemberCard SET FArrear = overdraft
UPDATE TImpMemberCard SET FState = 1
UPDATE TImpMemberCard SET FState = 3 WHERE status = 3
UPDATE TImpMemberCard SET FState = 4 WHERE status = 5
UPDATE A
SET A.FCompId = B.FCompId
FROM TImpMemberCard AS A,TImpCompany AS B
WHERE A.compId = b.id
SELECT * FROM TImpMemberCard WHERE status != 1
SELECT * FROM TImpMemberCard WHERE FMemID not in(SELECT FMemId FROM TMember)
--ÁƳÌ
ALTER TABLE TImpMemberCourse ADD FCardTypeId BIGINT
ALTER TABLE TImpMemberCourse ADD FItemId BIGINT
ALTER TABLE TImpMemberCourse ADD FRemainTimes INT
ALTER TABLE TImpMemberCourse ADD FPurTimes INT
ALTER TABLE TImpMemberCourse ADD FUsedTimes INT
ALTER TABLE TImpMemberCourse ADD FPurAmount DECIMAL(18,6)
ALTER TABLE TImpMemberCourse ADD FCreateDate DATETIME
ALTER TABLE TImpMemberCourse ADD FExpiredDate DATETIME
ALTER TABLE TImpMemberCourse ADD FCompId BIGINT
ALTER TABLE TImpMemberCourse ADD FCardId BIGINT
ALTER TABLE TImpMemberCourse ADD FMemId BIGINT
ALTER TABLE TImpMemberCourse ADD FMemo VARCHAR(1000)
SELECT * FROM TImpMemberCourse
UPDATE TImpMemberCourse SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL
UPDATE A
SET A.FMemId = B.FMemId
FROM TImpMemberCourse AS A,TImpMemberCard AS B
WHERE b.memId = a.memId
--ÒÔ¿¨Îª×¼
UPDATE A
SET A.FMemId = B.FMemId
FROM TImpMemberCourse AS A,TImpMemberCard AS B
WHERE b.memId = a.memId
AND b.cardNo = A.cardNo
SELECT * FROM TImpMemberCard WHERE
UPDATE TImpMemberCourse
SET FCreateDate = CREATEDATE,
FExpiredDate = ExpireDate,
FPurTimes = times,
FPurAmount = saleAmount,
FUsedTimes = cast(times as float) - remainTimes
UPDATE A
SET A.FCompId = B.FCompId
FROM TImpMemberCourse AS A,TImpCompany AS B
WHERE A.compId = b.id
SELECT * FROM TImpCardType
UPDATE TImpMemberCourse SET FCompId = dbo.FNCompID('001')
UPDATE A
SET A.FItemId = B.FId
FROM TImpMemberCourse AS A,TImpItem AS B
WHERE A.projectId = B.id
SELECT * FROM TCourse
INSERT INTO TCourse(FId,FNo,FName,FBriefCode,FItemId,FPackId,FSequence,FTypeId,FTimes,FFreeTimes,FDurable,FValidityPeriodUnit,FValidityPeriod,FCreateDate,FExpiredDate,FDescription,FEnabled,FPrice,FAmount,FCalcMode)
SELECT dbo.FNNewId(),
I.code + '',
I.name ,
dbo.FNGetFirstPinyin(name) AS FBriefCode,
I.FId 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 TImpItem AS I
ORDER BY name
SELECT * FROM TImpItem WHERE name = '½Ó·¢Ï´·¢'
UPDATE A
SET A.FCardTypeId = B.FId
FROM TImpMemberCourse AS A,TCourse AS B
WHERE A.FItemId = B.FItemId
select * from timpmember where fmemno is null
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 TImpMember
WHERE FMemNo IS NOT NULL
--ÒÔ¿¨Îª×¼
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,
FCardNo 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 TImpMemberCard
SELECT FCardNO FROM TImpMemberCard
GROUP BY FCardnO
HAVING sum(1) > 1
SELECT * FROM TImpMemberCard WHERE FCardNO ='000001'
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,
FState AS FState,
FCreateDate AS FCreateDate,
ISNULL(FExpiredDate,DATEADD(YEAR,100,FCreateDate)) AS FExpiredDate,
ISNULL(FRemainTimes,0) AS FTotalTimes,
0 AS FUsedTimes,
FCompId AS FSaleCompId,
0 AS FSaleBillId,
ISNULL(FMemo,'') AS FMemo
FROM TImpMemberCard
SELECT * FROM TImpMemberCard WHERE FMemId NOT IN(SELECT FMemId FROM TImpMEMBER)
GROUP BY FCardTypeId,FMemId,FCompId,FMemo,FCreateDate,FCardNO,FExpiredDate
,FRemainTimes
SELECT * FROM TImpMemberCard WHERE FCreateDate is null
TImpMemberCard
delete TImpMemberCard WHERE ShopName LIKE '%¶þ%'
SELECT compId FROM TImpMemberCard WHERE FCardTypeId IS NULL
INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo)
SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,3,FBalance,FBalance,A.FArrear,FCreateDate,NULL AS FExpiredDate,''
FROM TImpMemberCard 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,A.FArrear,getdate(),'´ÓºÌάÖе¼Èë'
FROM TImpMemberCard AS A
WHERE FCardId IN(SELECT FCardId FROM TMemberCard)
--ÔùË͵Ä
INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo)
SELECT A.FMemId,dbo.FNNewId(),A.FCardId AS FCardId,10,a.innerbestowal,a.innerbestowal,0,A.FCreateDate,NULL AS FExpiredDate,''
FROM TImpMemberCard AS A
WHERE a.innerbestowal != 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.innerbestowal,0,a.innerbestowal,0,getdate(),'´ÓºÌάÖе¼Èë'
FROM TImpMemberCard AS A
WHERE
a.innerbestowal != 0
--AND A.FCardId IN(SELECT FCardId FROM TMemberCard)
Ç·¿î
SELECT SUM(CAST(balance AS FLOAT)) FROM TImpMemberCard
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 TImpMemberCard AS A
WHERE A.FArrear > 0
SELECT * FROM TImpMemberCourse WHERE memID = '5a34befcc9e77c0007a24c5a'
SELECT * FROM TImpMember WHERE id = '5a34befcc9e77c0007a24c5a'
drop table TImpMemberCourse
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,FUsedTimes,FPurAmount,0,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,'´ÓºÌάµ¼Èë',1,0
FROM TImpMemberCourse AS A
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,FUsedTimes,0,FCompId,'DR','Import',0,'',0,getdate()
FROM TImpMemberCourse AS A
ALTER TABLE TImpMemberTransHist ADD FIndex BIGINT
UPDATE TImpMemberTransHist SET FIndex = dbo.FNNewId()
DELETE A
FROM TImpMemberTransHist AS A,
(
SELECT transId,projectId,empId,min(FIndex) as FIndex FROM TImpMemberTransHist
GROUP BY transId,projectId,empId
HAVING SUM(1) > 1
) AS B
WHERE A.transId = B.transId AND A.projectId = B.projectId AND A.empId = B.empId
AND A.FIndex != B.FIndex
SELECT transId,projectId,empId FROM TImpMemberTransHist
GROUP BY transId,projectId,empId
HAVING SUM(1) > 1
SELECT * FROM TImpMemberTransHist WHERE transId = '1586426316645339'
ALTER TABLE TImpMemberAcctHist ADD FMemId BIGINT
ALTER TABLE TImpMemberAcctHist ADD FCompId BIGINT
ALTER TABLE TImpMemberAcctHist ADD FCardId BIGINT
ALTER TABLE TImpMemberAcctHist ADD FCardTypeId BIGINT
UPDATE A
SET A.FMemId = B.FMemId,
A.FCompId = B.FCompId,
A.FCardId = B.FCardId,
A.FCardTypeId = B.FCardTypeId
FROM TImpMemberAcctHist AS A,TImpMemberCard AS B
WHERE A.cardId = B.id
SELECT * FROM TImpMemberCard
WHERE id NOT IN(
SELECT cardId FROM TImpMemberAcctHist WITH(NOLOCK)
)
DELETE TImpMemberCard
WHERE FCardId NOT IN(SELECT FCardId FROM TMemberCard)
AND id IN(
SELECT id FROM TImpMemberCard
GROUP BY id HAVING SUM(1) > 1
)
sp_rename 'TImpMemberTransHist','TImpMemberAcctHist'
INSERT INTO TMemberCardOldAcctHist(FId,FMemId,FCardId,FAcctId,
FTime,FCardTypeId,FCompId,FBizType,FTransNo,FInAmount,
FOutAmount,FBalance,FArrear,FRecordTime,FMemo)
INSERT INTO TMemberCardOldAcctHist(FId,FMemId,FCardId,FAcctId,FTime,FCardTypeId,FCompId,FBizType,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo)
SELECT dbo.FNNewId(),FMemId,FCardId,3,ISNULL(createDate,'1753-01-01'),FCardTypeId,ISNULL(FCompId,0),'[' + typeName + ']',isnull( smallNo,''),cast(rechargeAmount as float),case when type = 0 then cast(amount as float) else 0 end,isnull(balance,0),0,getdate(),remark
FROM TImpMemberAcctHist
SELECT * FROM TImpMemberAcctHist
SELECT * FROM TImpMemberTransHist
ALTER TABLE TImpMemberTradeHist ADD FMemId BIGINT
ALTER TABLE TImpMemberTradeHist ADD FCompId BIGINT
ALTER TABLE TImpMemberTradeHist ADD FCardId BIGINT
UPDATE A
SET A.FMemId = B.FMemId,
A.FCompId = B.FCompId,
A.FCardId = B.FCardId
FROM TImpMemberTradeHist AS A,TImpMemberCard AS B
WHERE A.cardId = B.id
INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo)
SELECT DBO.FNNewId(),A.FMemId,createDate,0,A.FCompId,'DR','Import','',remark,amount,1,amount,isnull(payName,''),isnull('','') + ',' + isnull('','') + ',' + isnull('',''),''
FROM TImpMemberTradeHist AS A
where type = 1
SELECT * FROM TImpMemberTradeHist where type = 1
ALTER TABLE TImpMemberConsumeHist ADD FMemId BIGINT
ALTER TABLE TImpMemberConsumeHist ADD FCompId BIGINT
ALTER TABLE TImpMemberConsumeHist ADD FCardId BIGINT
UPDATE A
SET A.FMemId = B.FMemId,
A.FCompId = B.FCompId,
A.FCardId = B.FCardId
FROM TImpMemberConsumeHist AS A,TImpMemberCard AS B
WHERE A.cardId = B.id
INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo)
SELECT DBO.FNNewId(),A.FMemId,createDate,0,A.FCompId,'DR','Import','',projectName,price,quantity,price,payName,isnull(empName,'') + ',' + isnull(empName1,'') + ',' + isnull(empName2,''),''
FROM TImpMemberConsumeHist AS A