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.
 
 
 
 
 

2204 lines
58 KiB

CREATE FUNCTION FNAcctId (@AcctNo VARCHAR(10))
RETURNS BIGINT
AS
BEGIN
return (SELECT FId FROM TPayAccount WHERE FNo = @AcctNo)
END
GO
CREATE FUNCTION FNCardTypeId (@No VARCHAR(10))
RETURNS BIGINT
AS
BEGIN
return (SELECT FId FROM TMemberCardType WHERE FNo = @No)
END
GO
--------模板
-----------------------------------------------------------------
--"Type"卡
-----------------------------------------------------------------
SELECT * FROM TMemberCardType WHERE FNo = 'CardTypeNo'
SELECT * FROM TPayAccount WHERE FNo = 'AcctNo'
------------------------------------------------------------------
--这些卡直接账户直接转
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard"Type"直接转
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE FTypeId = dbo.FNCardTypeId('CardTypeNo')
AND A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND NOT EXISTS(SELECT 1 FROM TMemberCardAccount AS O WHERE O.FCardId = A.FCardId AND O.FAcctId = 3)
AND B.FAcctId = dbo.FNAcctId('AcctNo')
ORDER BY A.FCardNo
SELECT * FROM TCard"Type"直接转
--转账户
UPDATE A
SET A.FAcctId = 3
FROM TCard"Type"直接转 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('AcctNo')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard"Type"直接转 AS B,TMemberCardAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('AcctNo')
--老账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard"Type"直接转 AS B,TMemberCardOldAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('AcctNo')
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard"Type"直接转)
--这些账户要转为新卡
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard"Type"转新卡
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND B.FAcctId = dbo.FNAcctId('AcctNo')
ORDER BY A.FCardNo
select * from TCard"Type"转新卡
--增加卡类别
UPDATE A
SET A.FNewCardTypeId = dbo.FNCardTypeId('CardTypeNo')
FROM TMemberCardAccount AS A
WHERE FId IN(SELECT FId FROM TCard"Type"转新卡)
--新增卡号
UPDATE A
SET A.FNewCardNo = B.FCardNo + '.CardTypeNo'
FROM TCard"Type"转新卡 as b, TMemberCardAccount AS A
WHERE B.FId = A.FId
AND A.FAcctId = dbo.FNAcctId('AcctNo')
SELECT * FROM TMemberCardAccount WHERE FId IN(SELECT FId FROM TCard"Type"转新卡)
--建立新卡
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FCardFaceNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId
)
SELECT
FNewCardId AS FCardId,
FNewCardNo AS FCardNo,
FNewCardNo AS FFaceNo,
FNewCardTypeId AS FTypeId,
1,
FNewCardCompId AS FCompId,
FMemId AS FMemId,
FNewCardState AS FState,
FNewCardCreateDate AS FCreateDate,
FNewCardExpiredDate AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FNewCardCompId AS FSaleCompId,
0 AS FSaleBillId
FROM TMemberCardAccount
WHERE FId IN(SELECT FId FROM TCard"Type"转新卡)
UPDATE A
SET A.FAcctId = 3,
A.FCardId = A.FNewCardId
FROM TCard"Type"转新卡 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('AcctNo')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard"Type"转新卡 AS B,TMemberCardAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('AcctNo')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
--老账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard"Type"转新卡 AS B,TMemberCardOldAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('AcctNo')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard"Type"转新卡)
-----------------------------------------------------------------------------------
--End OF 模板
----------------------------------------------------------------------------------
SELECT * FROM TPayAccount
SELECT A.FCardId,C.FCardNo,B.FNo,B.FName,P.FNo,P.FName
FROM TMemberCardAccount AS A,TMemberCard AS C,TPayAccount AS P,
TMemberCardType AS B
WHERE A.FCardId = C.FCardId
AND C.FTypeId = B.FId
AND P.FId = A.FAcctId
ORDER BY C.FCardNo
SELECT * FROM TConsumeBill
--增加新卡ID
ALTER TABLE TMemberCardAccount ADD FNewCardId BIGINT
ALTER TABLE TMemberCardAccount ADD FNewCardNo VARCHAR(50)
ALTER TABLE TMemberCardAccount ADD FNewCardTypeId BIGINT
ALTER TABLE TMemberCardAccount ADD FNewCardExpiredDate DATETIME
ALTER TABLE TMemberCardAccount ADD FNewCardCreateDate DATETIME
ALTER TABLE TMemberCardAccount ADD FNewCardState INT
ALTER TABLE TMemberCardAccount ADD FNewCardCompId BIGINT
ALTER TABLE TMemberCardAccount ADD FOldCardId BIGINT
UPDATE A
SET A.FNewCardExpiredDate = B.FExpiredDate,
A.FNewCardCreateDate = B.FCreateDate,
A.FNewCardState = B.FState,
A.FNewCardCompId = B.FCompId
FROM TMemberCardAccount AS A,TMemberCard AS B
WHERE A.FCardId = B.FCardId
UPDATE TMemberCardAccount SET FNewCardId = FId
UPDATE TMemberCardAccount SET FOldCardId = FCardId
SP_RENAME 'TMemberCardAccount.FOlcCardId','FOldCardId'
SELECT * FROM TMemberCardType WHERE FNo = 'D'
SELECT*FROM TConsumeBill
SELECT * INTO TMemberCardAccount_Bak FROM TMemberCardAccount
SELECT * INTO TMemberCardAcctHist_Bak FROM TMemberCardAcctHist
SELECT * INTO TMemberCard_Bak FROM TMemberCard
-----------------------------------------------------------------
--1000卡
-----------------------------------------------------------------
SELECT * FROM TMemberCardType WHERE FNo = 'D'
SELECT * FROM TPayAccount WHERE FNo = 'J'
------------------------------------------------------------------
--这些卡直接账户直接转
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard1000直接转
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE FTypeId = dbo.FNCardTypeId('D')
AND A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND NOT EXISTS(SELECT 1 FROM TMemberCardAccount AS O WHERE O.FCardId = A.FCardId AND O.FAcctId = 3)
AND B.FAcctId = dbo.FNAcctId('J')
ORDER BY A.FCardNo
SELECT * FROM TCard1000直接转
--转账户
UPDATE A
SET A.FAcctId = 3
FROM TCard1000直接转 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('J')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard1000直接转 AS B,TMemberCardAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('J')
--老账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard1000直接转 AS B,TMemberCardOldAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('J')
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard1000直接转)
--这些账户要转为新卡
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard1000转新卡
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND B.FAcctId = dbo.FNAcctId('J')
ORDER BY A.FCardNo
select * from TCard1000转新卡
--增加卡类别
UPDATE A
SET A.FNewCardTypeId = dbo.FNCardTypeId('D')
FROM TMemberCardAccount AS A
WHERE FId IN(SELECT FId FROM TCard1000转新卡)
--新增卡号
UPDATE A
SET A.FNewCardNo = B.FCardNo + '.D'
FROM TCard1000转新卡 as b, TMemberCardAccount AS A
WHERE B.FId = A.FId
AND A.FAcctId = dbo.FNAcctId('J')
SELECT * FROM TMemberCardAccount WHERE FId IN(SELECT FId FROM TCard1000转新卡)
--建立新卡
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FCardFaceNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId
)
SELECT
FNewCardId AS FCardId,
FNewCardNo AS FCardNo,
FNewCardNo AS FFaceNo,
FNewCardTypeId AS FTypeId,
1,
FNewCardCompId AS FCompId,
FMemId AS FMemId,
FNewCardState AS FState,
FNewCardCreateDate AS FCreateDate,
FNewCardExpiredDate AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FNewCardCompId AS FSaleCompId,
0 AS FSaleBillId
FROM TMemberCardAccount
WHERE FId IN(SELECT FId FROM TCard1000转新卡)
UPDATE A
SET A.FAcctId = 3,
A.FCardId = A.FNewCardId
FROM TCard1000转新卡 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('J')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard1000转新卡 AS B,TMemberCardAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('J')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
--老账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId
FROM TCard1000转新卡 AS B,TMemberCardOldAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('J')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard1000转新卡)
-----------------------------------------------------------------------------------
--End OF 1000
----------------------------------------------------------------------------------
--------模板
-----------------------------------------------------------------
--2000卡
-----------------------------------------------------------------
SELECT * FROM TMemberCardType WHERE FNo = 'E'
SELECT * FROM TPayAccount WHERE FNo = 'K'
------------------------------------------------------------------
--这些卡直接账户直接转
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard2000直接转
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE FTypeId = dbo.FNCardTypeId('E')
AND A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND NOT EXISTS(SELECT 1 FROM TMemberCardAccount AS O WHERE O.FCardId = A.FCardId AND O.FAcctId = 3)
AND B.FAcctId = dbo.FNAcctId('K')
ORDER BY A.FCardNo
SELECT * FROM TCard2000直接转
--转账户
UPDATE A
SET A.FAcctId = 3
FROM TCard2000直接转 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('K')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard2000直接转 AS B,TMemberCardAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('K')
--老账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard2000直接转 AS B,TMemberCardOldAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('K')
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard2000直接转)
--这些账户要转为新卡
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard2000转新卡
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND B.FAcctId = dbo.FNAcctId('K')
ORDER BY A.FCardNo
select * from TCard2000转新卡
--增加卡类别
UPDATE A
SET A.FNewCardTypeId = dbo.FNCardTypeId('E')
FROM TMemberCardAccount AS A
WHERE FId IN(SELECT FId FROM TCard2000转新卡)
--新增卡号
UPDATE A
SET A.FNewCardNo = B.FCardNo + '.E'
FROM TCard2000转新卡 as b, TMemberCardAccount AS A
WHERE B.FId = A.FId
AND A.FAcctId = dbo.FNAcctId('K')
SELECT * FROM TMemberCardAccount WHERE FId IN(SELECT FId FROM TCard2000转新卡)
--建立新卡
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FCardFaceNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId
)
SELECT
FNewCardId AS FCardId,
FNewCardNo AS FCardNo,
FNewCardNo AS FFaceNo,
FNewCardTypeId AS FTypeId,
1,
FNewCardCompId AS FCompId,
FMemId AS FMemId,
FNewCardState AS FState,
FNewCardCreateDate AS FCreateDate,
FNewCardExpiredDate AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FNewCardCompId AS FSaleCompId,
0 AS FSaleBillId
FROM TMemberCardAccount
WHERE FId IN(SELECT FId FROM TCard2000转新卡)
UPDATE A
SET A.FAcctId = 3,
A.FCardId = A.FNewCardId
FROM TCard2000转新卡 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('K')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard2000转新卡 AS B,TMemberCardAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('K')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
--老账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard2000转新卡 AS B,TMemberCardOldAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('K')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard2000转新卡)
-----------------------------------------------------------------------------------
--End OF 2000
----------------------------------------------------------------------------------
-----------------------------------------------------------------
--3600卡
-----------------------------------------------------------------
SELECT * FROM TMemberCardType WHERE FNo = 'F'
SELECT * FROM TPayAccount WHERE FNo = 'L'
------------------------------------------------------------------
--这些卡直接账户直接转
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard3600直接转
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE FTypeId = dbo.FNCardTypeId('F')
AND A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND NOT EXISTS(SELECT 1 FROM TMemberCardAccount AS O WHERE O.FCardId = A.FCardId AND O.FAcctId = 3)
AND B.FAcctId = dbo.FNAcctId('L')
ORDER BY A.FCardNo
SELECT * FROM TCard3600直接转
--转账户
UPDATE A
SET A.FAcctId = 3
FROM TCard3600直接转 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('L')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard3600直接转 AS B,TMemberCardAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('L')
--老账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard3600直接转 AS B,TMemberCardOldAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('L')
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard3600直接转)
--这些账户要转为新卡
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard3600转新卡
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND B.FAcctId = dbo.FNAcctId('L')
ORDER BY A.FCardNo
select * from TCard3600转新卡
--增加卡类别
UPDATE A
SET A.FNewCardTypeId = dbo.FNCardTypeId('F')
FROM TMemberCardAccount AS A
WHERE FId IN(SELECT FId FROM TCard3600转新卡)
--新增卡号
UPDATE A
SET A.FNewCardNo = B.FCardNo + '.F'
FROM TCard3600转新卡 as b, TMemberCardAccount AS A
WHERE B.FId = A.FId
AND A.FAcctId = dbo.FNAcctId('L')
SELECT * FROM TMemberCardAccount WHERE FId IN(SELECT FId FROM TCard3600转新卡)
--建立新卡
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FCardFaceNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId
)
SELECT
FNewCardId AS FCardId,
FNewCardNo AS FCardNo,
FNewCardNo AS FFaceNo,
FNewCardTypeId AS FTypeId,
1,
FNewCardCompId AS FCompId,
FMemId AS FMemId,
FNewCardState AS FState,
FNewCardCreateDate AS FCreateDate,
FNewCardExpiredDate AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FNewCardCompId AS FSaleCompId,
0 AS FSaleBillId
FROM TMemberCardAccount
WHERE FId IN(SELECT FId FROM TCard3600转新卡)
UPDATE A
SET A.FAcctId = 3,
A.FCardId = A.FNewCardId
FROM TCard3600转新卡 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('L')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard3600转新卡 AS B,TMemberCardAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('L')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
--老账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard3600转新卡 AS B,TMemberCardOldAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('L')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard3600转新卡)
-----------------------------------------------------------------------------------
--End OF 3600
----------------------------------------------------------------------------------
-----------------------------------------------------------------
--6000卡
-----------------------------------------------------------------
SELECT * FROM TMemberCardType WHERE FNo = 'G'
SELECT * FROM TPayAccount WHERE FNo = 'M'
------------------------------------------------------------------
--这些卡直接账户直接转
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard6000直接转
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE FTypeId = dbo.FNCardTypeId('G')
AND A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND NOT EXISTS(SELECT 1 FROM TMemberCardAccount AS O WHERE O.FCardId = A.FCardId AND O.FAcctId = 3)
AND B.FAcctId = dbo.FNAcctId('M')
ORDER BY A.FCardNo
SELECT * FROM TCard6000直接转
--转账户
UPDATE A
SET A.FAcctId = 3
FROM TCard6000直接转 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('M')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard6000直接转 AS B,TMemberCardAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('M')
--老账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard6000直接转 AS B,TMemberCardOldAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('M')
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard6000直接转)
--这些账户要转为新卡
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard6000转新卡
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND B.FAcctId = dbo.FNAcctId('M')
ORDER BY A.FCardNo
select * from TCard6000转新卡
--增加卡类别
UPDATE A
SET A.FNewCardTypeId = dbo.FNCardTypeId('G')
FROM TMemberCardAccount AS A
WHERE FId IN(SELECT FId FROM TCard6000转新卡)
--新增卡号
UPDATE A
SET A.FNewCardNo = B.FCardNo + '.G'
FROM TCard6000转新卡 as b, TMemberCardAccount AS A
WHERE B.FId = A.FId
AND A.FAcctId = dbo.FNAcctId('M')
SELECT * FROM TMemberCardAccount WHERE FId IN(SELECT FId FROM TCard6000转新卡)
--建立新卡
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FCardFaceNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId
)
SELECT
FNewCardId AS FCardId,
FNewCardNo AS FCardNo,
FNewCardNo AS FFaceNo,
FNewCardTypeId AS FTypeId,
1,
FNewCardCompId AS FCompId,
FMemId AS FMemId,
FNewCardState AS FState,
FNewCardCreateDate AS FCreateDate,
FNewCardExpiredDate AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FNewCardCompId AS FSaleCompId,
0 AS FSaleBillId
FROM TMemberCardAccount
WHERE FId IN(SELECT FId FROM TCard6000转新卡)
UPDATE A
SET A.FAcctId = 3,
A.FCardId = A.FNewCardId
FROM TCard6000转新卡 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('M')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId
FROM TCard6000转新卡 AS B,TMemberCardAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('M')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
--老账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId
FROM TCard6000转新卡 AS B,TMemberCardOldAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('M')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard6000转新卡)
-----------------------------------------------------------------------------------
--End OF 6000
----------------------------------------------------------------------------------
-----------------------------------------------------------------
--10000卡
-----------------------------------------------------------------
SELECT * FROM TMemberCardType WHERE FNo = 'H'
SELECT * FROM TPayAccount WHERE FNo = 'N'
------------------------------------------------------------------
--这些卡直接账户直接转
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard10000直接转
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE FTypeId = dbo.FNCardTypeId('H')
AND A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND NOT EXISTS(SELECT 1 FROM TMemberCardAccount AS O WHERE O.FCardId = A.FCardId AND O.FAcctId = 3)
AND B.FAcctId = dbo.FNAcctId('N')
ORDER BY A.FCardNo
SELECT * FROM TCard10000直接转
--转账户
UPDATE A
SET A.FAcctId = 3
FROM TCard10000直接转 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('N')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard10000直接转 AS B,TMemberCardAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('N')
--老账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard10000直接转 AS B,TMemberCardOldAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('N')
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard10000直接转)
--这些账户要转为新卡
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard10000转新卡
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND B.FAcctId = dbo.FNAcctId('N')
ORDER BY A.FCardNo
select * from TCard10000转新卡
--增加卡类别
UPDATE A
SET A.FNewCardTypeId = dbo.FNCardTypeId('H')
FROM TMemberCardAccount AS A
WHERE FId IN(SELECT FId FROM TCard10000转新卡)
--新增卡号
UPDATE A
SET A.FNewCardNo = B.FCardNo + '.H'
FROM TCard10000转新卡 as b, TMemberCardAccount AS A
WHERE B.FId = A.FId
AND A.FAcctId = dbo.FNAcctId('N')
SELECT * FROM TMemberCardAccount WHERE FId IN(SELECT FId FROM TCard10000转新卡)
--建立新卡
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FCardFaceNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId
)
SELECT
FNewCardId AS FCardId,
FNewCardNo AS FCardNo,
FNewCardNo AS FFaceNo,
FNewCardTypeId AS FTypeId,
1,
FNewCardCompId AS FCompId,
FMemId AS FMemId,
FNewCardState AS FState,
FNewCardCreateDate AS FCreateDate,
FNewCardExpiredDate AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FNewCardCompId AS FSaleCompId,
0 AS FSaleBillId
FROM TMemberCardAccount
WHERE FId IN(SELECT FId FROM TCard10000转新卡)
UPDATE A
SET A.FAcctId = 3,
A.FCardId = A.FNewCardId
FROM TCard10000转新卡 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('N')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard10000转新卡 AS B,TMemberCardAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('N')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
--老账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard10000转新卡 AS B,TMemberCardOldAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('N')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard10000转新卡)
-----------------------------------------------------------------------------------
--End OF 10000
----------------------------------------------------------------------------------
-----------------------------------------------------------------
--20000卡
-----------------------------------------------------------------
SELECT * FROM TMemberCardType WHERE FNo = 'I'
SELECT * FROM TPayAccount WHERE FNo = 'O'
------------------------------------------------------------------
--这些卡直接账户直接转
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard20000直接转
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE FTypeId = dbo.FNCardTypeId('I')
AND A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND NOT EXISTS(SELECT 1 FROM TMemberCardAccount AS O WHERE O.FCardId = A.FCardId AND O.FAcctId = 3)
AND B.FAcctId = dbo.FNAcctId('O')
ORDER BY A.FCardNo
SELECT * FROM TCard20000直接转
--转账户
UPDATE A
SET A.FAcctId = 3
FROM TCard20000直接转 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('O')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard20000直接转 AS B,TMemberCardAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('O')
--老账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard20000直接转 AS B,TMemberCardOldAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('O')
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard20000直接转)
--这些账户要转为新卡
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard20000转新卡
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND B.FAcctId = dbo.FNAcctId('O')
ORDER BY A.FCardNo
select * from TCard20000转新卡
--增加卡类别
UPDATE A
SET A.FNewCardTypeId = dbo.FNCardTypeId('I')
FROM TMemberCardAccount AS A
WHERE FId IN(SELECT FId FROM TCard20000转新卡)
--新增卡号
UPDATE A
SET A.FNewCardNo = B.FCardNo + '.I'
FROM TCard20000转新卡 as b, TMemberCardAccount AS A
WHERE B.FId = A.FId
AND A.FAcctId = dbo.FNAcctId('O')
SELECT * FROM TMemberCardAccount WHERE FId IN(SELECT FId FROM TCard20000转新卡)
--建立新卡
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FCardFaceNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId
)
SELECT
FNewCardId AS FCardId,
FNewCardNo AS FCardNo,
FNewCardNo AS FFaceNo,
FNewCardTypeId AS FTypeId,
1,
FNewCardCompId AS FCompId,
FMemId AS FMemId,
FNewCardState AS FState,
FNewCardCreateDate AS FCreateDate,
FNewCardExpiredDate AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FNewCardCompId AS FSaleCompId,
0 AS FSaleBillId
FROM TMemberCardAccount
WHERE FId IN(SELECT FId FROM TCard20000转新卡)
UPDATE A
SET A.FAcctId = 3,
A.FCardId = A.FNewCardId
FROM TCard20000转新卡 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('O')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard20000转新卡 AS B,TMemberCardAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('O')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
--老账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard20000转新卡 AS B,TMemberCardOldAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('O')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard20000转新卡)
-----------------------------------------------------------------------------------
--End OF 20000
----------------------------------------------------------------------------------
-----------------------------------------------------------------
--38000卡
-----------------------------------------------------------------
SELECT * FROM TMemberCardType WHERE FNo = 'S'
SELECT * FROM TPayAccount WHERE FNo = 'S'
SELECT * FROM TMemberCardAccount WHERE FAcctId= dbo.FNAcctId('S')
------------------------------------------------------------------
--38000元
--这些卡直接账户直接转
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard38000直接转
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE FTypeId = dbo.FNCardTypeId('S')
AND A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND NOT EXISTS(SELECT 1 FROM TMemberCardAccount AS O WHERE O.FCardId = A.FCardId AND O.FAcctId = 3)
AND B.FAcctId = dbo.FNAcctId('S')
ORDER BY A.FCardNo
SELECT * FROM TCard38000直接转
UPDATE A
SET A.FAcctId = 3
FROM TCard38000直接转 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('S')
AND A.FId = B.FId
UPDATE A
SET A.FAcctId = 3
FROM TCard38000直接转 AS B,TMemberCardAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('S')
AND A.FId = B.FId
UPDATE A
SET A.FAcctId = 3
FROM TCard38000直接转 AS B,TMemberCardOldAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('S')
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard38000直接转)
--38000万元
--这些账户要转为新卡
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard38000转新卡
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND B.FAcctId = dbo.FNAcctId('S')
ORDER BY A.FCardNo
select * from TCard38000转新卡
--增加卡类别
UPDATE A
SET A.FNewCardTypeId = dbo.FNCardTypeId('S')
FROM TMemberCardAccount AS A
WHERE FId IN(SELECT FId FROM TCard38000转新卡)
--新增卡号
UPDATE A
SET A.FNewCardNo = B.FCardNo + '.S'
FROM TCard38000转新卡 as b, TMemberCardAccount AS A
WHERE B.FId = A.FId
AND A.FAcctId = dbo.FNAcctId('S')
SELECT * FROM TMemberCardAccount WHERE FId IN(SELECT FId FROM TCard38000转新卡)
--建立新卡
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FCardFaceNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId
)
SELECT
FNewCardId AS FCardId,
FNewCardNo AS FCardNo,
FNewCardNo AS FFaceNo,
FNewCardTypeId AS FTypeId,
1,
FNewCardCompId AS FCompId,
FMemId AS FMemId,
FNewCardState AS FState,
FNewCardCreateDate AS FCreateDate,
FNewCardExpiredDate AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FNewCardCompId AS FSaleCompId,
0 AS FSaleBillId
FROM TMemberCardAccount
WHERE FId IN(SELECT FId FROM TCard38000转新卡)
UPDATE A
SET A.FAcctId = 3,
A.FCardId = A.FNewCardId
FROM TCard38000转新卡 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('S')
AND A.FId = B.FId
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard38000转新卡 AS B,TMemberCardAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('S')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard38000转新卡 AS B,TMemberCardOldAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('S')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard38000转新卡)
-----------------------------------------------------------------------------------
--End OF 38000
----------------------------------------------------------------------------------
--UPDATE T
-- SET T.FCardId = C.FNewCardId,
-- T.FCardNo = C.FNewCardNo,
-- T.FCardTypeId = C.FNewCardTypeId
-- FROM TCard6000转新卡 AS B,
-- TConsumeItemPayment AS A,
-- TConsumeBill AS T,
-- TMemberCardAccount AS C
-- WHERE T.FCardId = B.FCardId
-- AND A.FPayTypeId = B.FAcctId
-- AND T.FBillId = T.FBillId
-- AND C.FOldCardId = T.FCardId
-- AND C.FId = B.FId
---- UPDATE TConsumeBill SET FCardNo = '986803.1',FCardId = 8720287399098755275
---- WHERE FBillNo = '0111602280012'
----SELECT * FROM TMemberCard WHERE FCardNo = '986803.1'
--UPDATE A
-- SET A.FPayTypeId = 3,
-- A.FCardId = C.FNewCardId
-- FROM TCard6000转新卡 AS B,
-- TConsumeItemPayment AS A,
-- TMemberCardAccount AS C
-- WHERE a.FCardId = B.FCardId
-- AND A.FPayTypeId = B.FAcctId
-- AND C.FOldCardId = a.FCardId
-- AND C.FId = B.FId
--UPDATE A
-- SET A.FPayTypeId = 3,
-- A.FCardId = C.FNewCardId
-- FROM TCard6000转新卡 AS B,
-- TConsumeGoodsPayment AS A,
-- TConsumeBill AS T,
-- TMemberCardAccount AS C
-- WHERE T.FCardId = B.FCardId
-- AND A.FPayTypeId = B.FAcctId
-- AND T.FBillId = T.FBillId
-- AND C.FOldCardId = T.FCardId
-- AND C.FId = B.FId
----------------END
-----------------------------------------------------------------
--50000卡
-----------------------------------------------------------------
SELECT * FROM TMemberCardType WHERE FNo = 'X'
SELECT * FROM TPayAccount WHERE FNo = 'F'
------------------------------------------------------------------
--这些卡直接账户直接转
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard50000直接转
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE FTypeId = dbo.FNCardTypeId('X')
AND A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND NOT EXISTS(SELECT 1 FROM TMemberCardAccount AS O WHERE O.FCardId = A.FCardId AND O.FAcctId = 3)
AND B.FAcctId = dbo.FNAcctId('F')
ORDER BY A.FCardNo
SELECT * FROM TCard50000直接转
--转账户
UPDATE A
SET A.FAcctId = 3
FROM TCard50000直接转 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('F')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard50000直接转 AS B,TMemberCardAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('F')
--老账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard50000直接转 AS B,TMemberCardOldAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('F')
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard50000直接转)
--这些账户要转为新卡
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard50000转新卡
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND B.FAcctId = dbo.FNAcctId('F')
ORDER BY A.FCardNo
select * from TCard50000转新卡
--增加卡类别
UPDATE A
SET A.FNewCardTypeId = dbo.FNCardTypeId('x')
FROM TMemberCardAccount AS A
WHERE FId IN(SELECT FId FROM TCard50000转新卡)
--新增卡号
UPDATE A
SET A.FNewCardNo = B.FCardNo + '.X'
FROM TCard50000转新卡 as b, TMemberCardAccount AS A
WHERE B.FId = A.FId
AND A.FAcctId = dbo.FNAcctId('F')
SELECT * FROM TMemberCardAccount WHERE FId IN(SELECT FId FROM TCard50000转新卡)
--建立新卡
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FCardFaceNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId
)
SELECT
FNewCardId AS FCardId,
FNewCardNo AS FCardNo,
FNewCardNo AS FFaceNo,
FNewCardTypeId AS FTypeId,
1,
FNewCardCompId AS FCompId,
FMemId AS FMemId,
FNewCardState AS FState,
FNewCardCreateDate AS FCreateDate,
FNewCardExpiredDate AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FNewCardCompId AS FSaleCompId,
0 AS FSaleBillId
FROM TMemberCardAccount
WHERE FId IN(SELECT FId FROM TCard50000转新卡)
UPDATE A
SET A.FAcctId = 3,
A.FCardId = A.FNewCardId
FROM TCard50000转新卡 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('f')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard50000转新卡 AS B,TMemberCardAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('f')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
--老账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard50000转新卡 AS B,TMemberCardOldAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('f')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard50000转新卡)
-----------------------------------------------------------------------------------
--End OF 50000
----------------------------------------------------------------------------------
SELECT * FROM TMemberCardACCOUNT WHERE FAcctId = dbo.FNAcctId('D')
SELECT * FROM TMemberCard WHERE FCardId = 4736404752336390445
-----------------------------------------------------------------
--洁毛卡
-----------------------------------------------------------------
SELECT * FROM TMemberCardType WHERE FNo = 'P'
SELECT * FROM TPayAccount WHERE FNo = 'E'
------------------------------------------------------------------
--这些卡直接账户直接转
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard洁毛直接转
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE FTypeId = dbo.FNCardTypeId('P')
AND A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND NOT EXISTS(SELECT 1 FROM TMemberCardAccount AS O WHERE O.FCardId = A.FCardId AND O.FAcctId = 3)
AND B.FAcctId = dbo.FNAcctId('E')
ORDER BY A.FCardNo
SELECT * FROM TCard洁毛直接转
--转账户
UPDATE A
SET A.FAcctId = 3
FROM TCard洁毛直接转 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('E')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard洁毛直接转 AS B,TMemberCardAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('E')
--老账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard洁毛直接转 AS B,TMemberCardOldAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('E')
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard洁毛直接转)
--这些账户要转为新卡
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard洁毛转新卡
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND B.FAcctId = dbo.FNAcctId('E')
ORDER BY A.FCardNo
select * from TCard洁毛转新卡
--增加卡类别
UPDATE A
SET A.FNewCardTypeId = dbo.FNCardTypeId('P')
FROM TMemberCardAccount AS A
WHERE FId IN(SELECT FId FROM TCard洁毛转新卡)
--新增卡号
UPDATE A
SET A.FNewCardNo = B.FCardNo + '.P'
FROM TCard洁毛转新卡 as b, TMemberCardAccount AS A
WHERE B.FId = A.FId
AND A.FAcctId = dbo.FNAcctId('E')
SELECT * FROM TMemberCardAccount WHERE FId IN(SELECT FId FROM TCard洁毛转新卡)
--建立新卡
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FCardFaceNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId
)
SELECT
FNewCardId AS FCardId,
FNewCardNo AS FCardNo,
FNewCardNo AS FFaceNo,
FNewCardTypeId AS FTypeId,
1,
FNewCardCompId AS FCompId,
FMemId AS FMemId,
FNewCardState AS FState,
FNewCardCreateDate AS FCreateDate,
FNewCardExpiredDate AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FNewCardCompId AS FSaleCompId,
0 AS FSaleBillId
FROM TMemberCardAccount
WHERE FId IN(SELECT FId FROM TCard洁毛转新卡)
UPDATE A
SET A.FAcctId = 3,
A.FCardId = A.FNewCardId
FROM TCard洁毛转新卡 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('E')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard洁毛转新卡 AS B,TMemberCardAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('E')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
--老账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard洁毛转新卡 AS B,TMemberCardOldAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('E')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard洁毛转新卡)
-----------------------------------------------------------------------------------
--End OF 洁毛
----------------------------------------------------------------------------------
-----------------------------------------------------------------
--超声刀卡
-----------------------------------------------------------------
SELECT * FROM TMemberCardType WHERE FNo = 'CSD'
SELECT * FROM TPayAccount WHERE FNo = 'DZ'
------------------------------------------------------------------
--这些卡直接账户直接转
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard超声刀直接转
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE FTypeId = dbo.FNCardTypeId('CSD')
AND A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND NOT EXISTS(SELECT 1 FROM TMemberCardAccount AS O WHERE O.FCardId = A.FCardId AND O.FAcctId = 3)
AND B.FAcctId = dbo.FNAcctId('DZ')
ORDER BY A.FCardNo
SELECT * FROM TCard超声刀直接转
--转账户
UPDATE A
SET A.FAcctId = 3
FROM TCard超声刀直接转 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('DZ')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard超声刀直接转 AS B,TMemberCardAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('DZ')
--老账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard超声刀直接转 AS B,TMemberCardOldAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('DZ')
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard超声刀直接转)
--这些账户要转为新卡
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard超声刀转新卡
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND B.FAcctId = dbo.FNAcctId('DZ')
ORDER BY A.FCardNo
select * from TCard超声刀转新卡
--增加卡类别
UPDATE A
SET A.FNewCardTypeId = dbo.FNCardTypeId('CSD')
FROM TMemberCardAccount AS A
WHERE FId IN(SELECT FId FROM TCard超声刀转新卡)
--新增卡号
UPDATE A
SET A.FNewCardNo = B.FCardNo + '.CardTypeNo'
FROM TCard超声刀转新卡 as b, TMemberCardAccount AS A
WHERE B.FId = A.FId
AND A.FAcctId = dbo.FNAcctId('DZ')
SELECT * FROM TMemberCardAccount WHERE FId IN(SELECT FId FROM TCard超声刀转新卡)
--建立新卡
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FCardFaceNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId
)
SELECT
FNewCardId AS FCardId,
FNewCardNo AS FCardNo,
FNewCardNo AS FFaceNo,
FNewCardTypeId AS FTypeId,
1,
FNewCardCompId AS FCompId,
FMemId AS FMemId,
FNewCardState AS FState,
FNewCardCreateDate AS FCreateDate,
FNewCardExpiredDate AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FNewCardCompId AS FSaleCompId,
0 AS FSaleBillId
FROM TMemberCardAccount
WHERE FId IN(SELECT FId FROM TCard超声刀转新卡)
UPDATE A
SET A.FAcctId = 3,
A.FCardId = A.FNewCardId
FROM TCard超声刀转新卡 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('DZ')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard超声刀转新卡 AS B,TMemberCardAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('DZ')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
--老账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard超声刀转新卡 AS B,TMemberCardOldAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('DZ')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard超声刀转新卡)
-----------------------------------------------------------------------------------
--End OF 超声刀
----------------------------------------------------------------------------------
-----------------------------------------------------------------
--"店庆"卡
-----------------------------------------------------------------
SELECT * FROM TMemberCardType WHERE FNo = 'J'
SELECT * FROM TPayAccount WHERE FNo = 'C'
------------------------------------------------------------------
--这些卡直接账户直接转
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard店庆直接转
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE FTypeId = dbo.FNCardTypeId('J')
AND A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND NOT EXISTS(SELECT 1 FROM TMemberCardAccount AS O WHERE O.FCardId = A.FCardId AND O.FAcctId = 3)
AND B.FAcctId = dbo.FNAcctId('C')
ORDER BY A.FCardNo
SELECT * FROM TCard店庆直接转
--转账户
UPDATE A
SET A.FAcctId = 3
FROM TCard店庆直接转 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('C')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard店庆直接转 AS B,TMemberCardAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('C')
--老账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard店庆直接转 AS B,TMemberCardOldAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('C')
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard店庆直接转)
--这些账户要转为新卡
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard店庆转新卡
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND B.FAcctId = dbo.FNAcctId('C')
ORDER BY A.FCardNo
select * from TCard店庆转新卡
--增加卡类别
UPDATE A
SET A.FNewCardTypeId = dbo.FNCardTypeId('J')
FROM TMemberCardAccount AS A
WHERE FId IN(SELECT FId FROM TCard店庆转新卡)
--新增卡号
UPDATE A
SET A.FNewCardNo = B.FCardNo + '.J'
FROM TCard店庆转新卡 as b, TMemberCardAccount AS A
WHERE B.FId = A.FId
AND A.FAcctId = dbo.FNAcctId('C')
SELECT * FROM TMemberCardAccount WHERE FId IN(SELECT FId FROM TCard店庆转新卡)
--建立新卡
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FCardFaceNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId
)
SELECT
FNewCardId AS FCardId,
FNewCardNo AS FCardNo,
FNewCardNo AS FFaceNo,
FNewCardTypeId AS FTypeId,
1,
FNewCardCompId AS FCompId,
FMemId AS FMemId,
FNewCardState AS FState,
FNewCardCreateDate AS FCreateDate,
FNewCardExpiredDate AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FNewCardCompId AS FSaleCompId,
0 AS FSaleBillId
FROM TMemberCardAccount
WHERE FId IN(SELECT FId FROM TCard店庆转新卡)
UPDATE A
SET A.FAcctId = 3,
A.FCardId = A.FNewCardId
FROM TCard店庆转新卡 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('C')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard店庆转新卡 AS B,TMemberCardAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('C')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
--老账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard店庆转新卡 AS B,TMemberCardOldAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('C')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard店庆转新卡)
-----------------------------------------------------------------------------------
--End OF 店庆
----------------------------------------------------------------------------------
------------------------------------------------------------------
--这些卡直接账户直接转
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard睫毛直接转
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE FTypeId = dbo.FNCardTypeId('OC')
AND A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND NOT EXISTS(SELECT 1 FROM TMemberCardAccount AS O WHERE O.FCardId = A.FCardId AND O.FAcctId = 3)
AND B.FAcctId = dbo.FNAcctId('D')
ORDER BY A.FCardNo
SELECT * FROM TCard睫毛直接转
--转账户
UPDATE A
SET A.FAcctId = 3
FROM TCard睫毛直接转 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('D')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard睫毛直接转 AS B,TMemberCardAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('D')
--老账户历史
UPDATE A
SET A.FAcctId = 3
FROM TCard睫毛直接转 AS B,TMemberCardOldAcctHist AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('D')
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard睫毛直接转)
--这些账户要转为新卡
SELECT B.FId,A.FCardId,A.FCardNo,B.FAcctId,P.FName,B.FBalance INTO TCard睫毛转新卡
FROM TMemberCard AS A,
TMemberCardAccount AS B,
TPayAccount AS P
WHERE A.FCardId = B.FCardId
AND B.FAcctId = P.FId
AND B.FAcctId != 3
AND B.FAcctId = dbo.FNAcctId('D')
ORDER BY A.FCardNo
select * from TCard睫毛转新卡
--增加卡类别
UPDATE A
SET A.FNewCardTypeId = dbo.FNCardTypeId('OC')
FROM TMemberCardAccount AS A
WHERE FId IN(SELECT FId FROM TCard睫毛转新卡)
--新增卡号
UPDATE A
SET A.FNewCardNo = B.FCardNo + '.OC'
FROM TCard睫毛转新卡 as b, TMemberCardAccount AS A
WHERE B.FId = A.FId
AND A.FAcctId = dbo.FNAcctId('D')
SELECT * FROM TMemberCardAccount WHERE FId IN(SELECT FId FROM TCard睫毛转新卡)
--建立新卡
INSERT INTO TMemberCard(
FCardId,
FCardNo,
FCardFaceNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId
)
SELECT
FNewCardId AS FCardId,
FNewCardNo AS FCardNo,
FNewCardNo AS FFaceNo,
FNewCardTypeId AS FTypeId,
1,
FNewCardCompId AS FCompId,
FMemId AS FMemId,
FNewCardState AS FState,
FNewCardCreateDate AS FCreateDate,
FNewCardExpiredDate AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FNewCardCompId AS FSaleCompId,
0 AS FSaleBillId
FROM TMemberCardAccount
WHERE FId IN(SELECT FId FROM TCard睫毛转新卡)
UPDATE A
SET A.FAcctId = 3,
A.FCardId = A.FNewCardId
FROM TCard睫毛转新卡 AS B,TMemberCardAccount AS A
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('D')
AND A.FId = B.FId
--账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard睫毛转新卡 AS B,TMemberCardAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('D')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
--老账户历史
UPDATE A
SET A.FAcctId = 3,
A.FCardId = C.FNewCardId,
A.FCardTypeId = C.FNewCardTypeId
FROM TCard睫毛转新卡 AS B,TMemberCardOldAcctHist AS A,TMemberCardAccount AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = dbo.FNAcctId('D')
AND A.FCardId = C.FOldCardId
AND C.FId = B.FId
UPDATE TMemberCardAccount SET FOk = 1 WHERE FId IN(SELECT FId FROM TCard睫毛转新卡)
-----------------------------------------------------------------------------------
--End OF 睫毛
----------------------------------------------------------------------------------
SELECT * FROM TMemberCardAccount WHERE FAcctId NOT IN(3,5816181355469595633)
SELECT * FROM TPayAccount WHERE FId = 8766359884515282142
AND FCardId IN(SELECT FCardId FROM TMemberCard WHERE FState = 1)
SELECT * FROM TMemberCard WHERE FCardId = 7873590298966444083
UPDATE A SET A.FEnabled = B.FEnabled FROM TPayAccountSub AS A,TPayAccount AS B
WHERE A.FPayAccountId = B.FId
SELECT * FROM TPayAccountSub
/*
SELECT * FROM TConsumeItemPayment
SELECT * FROM TPayAccount WHERE FId = 5816181355469595633
SELECT * FROM TMemberCardAccount WHERE FAcctId = 3
UPDATE TMemberCardAccount SET FAcctId = 3 WHERE FAcctId = 6
UPDATE TMemberCardAcctHist SET FAcctId = 3 WHERE FAcctId = 6
UPDATE TMemberCardOldAcctHist SET FAcctId = 3 WHERE FAcctId = 6
SELECT * FROM TMemberCardAccount WHERE FAcctId = 7420045379273129994
SELECT * FROM TMemberCardOldAcctHist WHERE FAcctId = 7420045379273129994
SELECT * FROM TMemberCard WHERE FCardID = 7004306889657470830
SELECT * FROM TConsumeBill WHERE FCardTypeId = 5188146770730811392
SELECT * FROM TConsumeBill AS T,TConsumeItemPayment AS P
WHERE EXISTS(SELECT * from TCard银卡1万直接转 AS A WHERE A.FCardId = T.FCardId AND P.FPayTypeId = A.FAcctId)
AND T.FBillId = P.FBillId
SELECT FId,FNo,FName INTO TPayAccountError FROM TPayAccount
WHERE 1=0
INSERT TPayAccountError
SELECT 44444 ,'44444' ,'不存在的储值账户'
SELECT * FROM TCard1000直接转
SELECT * FROM TMemberCardOldAcctHist AS H
WHERE EXISTS(SELECT 1 FROM TMemberCardAccount AS A WHERE A.FCardID = H.FCardId)
AND H.FAcctId = 3
SELECT * FROM TMemberCardOldAcctHist AS H
--这些储值账户是不存在的,可能是修改了
UPDATE H
SET H.FAcctId = 44444
SELECT *
FROM TMemberCardOldAcctHist AS H
WHERE NOT EXISTS(SELECT 1 FROM TMemberCardAccount AS A WHERE A.FCardID = H.FCardId AND A.FAcctId = H.FAcctId )
AND H.FAcctId = 3
AND H.FCardId = 5399231790984788126
SELECT * FROM TMemberCardOldAcctHist AS H
WHERE EXISTS(SELECT 1 FROM TCard银卡1万直接转 AS A WHERE A.FCardID = H.FCardId)
AND H.FAcctId = 3
AND H.FCardId = 5399231790984788126
SELECT * FROM TMemberCard WHERE FCardId = 4692986448666566486
UPDATE TMemberCardAccount
SET FCardTypeId = (SELECT FId FROM TMemberCardType WHERE FNo = 'D')
WHERE FAcctId = (SELECT FId FROM TPayAccount WHERE FNo = 'J')
*/
--删除没有账户历史的卡
SELECT *--INTO TMemberCard_Deleted_OC
FROM TMemberCard AS C
WHERE NOT EXISTS(SELECT 1 FROM TMemberCardOldAcctHist AS D WHERE D.FCardId = C.FCardId)
AND NOT EXISTS(SELECT 1 FROM TMemberCardAccount AS E WHERE E.FCardId = C.FCardId AND E.FBalance > 0)
--AND FCardNo LIKE '%OC'
DELETE TMemberCardAccount WHERE FCardId IN(SELECT FCardId FROM TMemberCard_Deleted_OC)
DELETE TMemberCard WHERE FCardId IN(SELECT FCardId FROM TMemberCard_Deleted_OC)
UPDATE A
SET A.FMemo = B.FMemo
FROM TMember AS A,TMemberCard AS B
WHERE A.FMemId = B.FMemId
AND B.FMemo != ''
SELECT * FROM TMember
UPDATE TMemberCard SET FMemo = ''