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/金指合并/SQLQuery1.sql

239 lines
5.4 KiB

1 year ago
DROP TABLE TSameMember
SEL
SELECT FMobilePhone,FName,SUM(1) AS FCount,MIN(FIndex) AS FCreateDate INTO TSameMember
FROM TMember
WHERE FMobilePhone != ''
AND dbo.FNIsMobile(FMobilePhone) = 1
GROUP BY FMobilePhone,FName
HAVING (COUNT(1) > 1)
ORDER BY FMobilePhone DESC
DROP TABLE TSameMemberMaster
SELECT * INTO TSameMemberMaster FROM TMember AS A
WHERE EXISTS(SELECT 1 FROM TSameMember AS B WHERE B.FMobilePhone = A.FMobilePhone AND A.FName = B.FName
AND B.FCreateDate = A.FIndex)
SELECT * FROM TMember AS A
WHERE EXISTS(SELECT 1 FROM TSameMember AS B WHERE B.FMobilePhone = A.FMobilePhone AND A.FName = B.FName )
SELECT 4082-2497
SELECT COUNT(1 ) FROM TSameMember
ORDER BY SUM(1) DESC
SELECT IDENTITY(INT,1,1) AS FIndex,FMemId INTO #Member FROM TMember
ORDER BY FMobilePhone,FName,FCreateDate
UPDATE A
SET A.FIndex = B.FIndex
FROM TMember AS A,#Member AS B
WHERE A.FMemId = B.FMemId
SELECT * FROM TMember
SELECT FMobilePhone,FName,SUM(1) AS FCount,MIN(FCreateDate) AS FCreateDate INTO TSameMember
FROM TMember
WHERE FMobilePhone != ''
AND dbo.FNIsMobile(FMobilePhone) = 1
GROUP BY FMobilePhone,FName
HAVING (COUNT(1) > 1)
ORDER BY FMobilePhone DESC
ALTER TABLE TMember ADD FNewMemId BIGINT,FNewMemNo VARCHAR(30)
UPDATE A
SET A.FNewMemId = B.FMemId,
A.FNewMemNo = B.FMemNo
FROM TMember AS A,TSameMemberMaster AS B
WHERE A.FMobilePhone = B.FMobilePhone
AND A.FName = B.FName
AND A.FIndex != B.FIndex
SELECT * FROM TMember WHERE FNewMemId IS NOT NULL
SELECT * FROM
--<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SELECT * FROM TMember WHERE FNewMemId != 0
UPDATE TMember SET FNewMemId = 0 WHERE FNewMemId IS NULL
UPDATE TMember SET FNewMemNo = '' WHERE FNewMemNo IS NULL
UPDATE A
SET A.FMemo = A.FMemo + '[<EFBFBD>Ѿ<EFBFBD><EFBFBD>ϲ<EFBFBD><EFBFBD><EFBFBD>' + A.FNewMemNo + ']'
FROM TMember AS A
WHERE FNewMemId IS NOT NULL
UPDATE A
SET A.FMemNo = A.FMemNo + '[<EFBFBD>Ѿ<EFBFBD><EFBFBD>ϲ<EFBFBD><EFBFBD><EFBFBD>' + A.FNewMemNo + ']'
FROM TMember AS A
WHERE FNewMemId IS NOT NULL
UPDATE TMember SET FState = 3,FMemNo = FMemNo + '[<EFBFBD>Ѻϲ<EFBFBD>]'
WHERE FNewMemId != 0
--<EFBFBD><EFBFBD>
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberCard AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
--<EFBFBD>˻<EFBFBD>
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberCardAccount AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
--<EFBFBD>˻<EFBFBD><EFBFBD><EFBFBD>ʷ
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberCardAcctHist AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberCardOldAcctHist AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
--<EFBFBD>Ƴ<EFBFBD>
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberCourse AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
--<EFBFBD>Ƴ<EFBFBD><EFBFBD><EFBFBD>ʷ
--<EFBFBD>Ƴ<EFBFBD>
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberCourseHist AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʷ
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberTransHist AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberOldTransHist AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʷ֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʷ
--<EFBFBD>Ƴ<EFBFBD>
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberTransHistPayment AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʷ
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberPointHist AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
--Ƿ<EFBFBD><EFBFBD>
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberArrear AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
--Ƿ<EFBFBD><EFBFBD>
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberArrearEmployee AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
--Ƿ<EFBFBD><EFBFBD>
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberSaleBill AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FMemId = B.FNewMemId,
A.FMemNo = B.FNewMemNo
FROM TMemberRemind AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FMemId = B.FNewMemId,
A.FMemNo = B.FNewMemNo
FROM TConsumeBill AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FMemId = B.FNewMemId,
A.FMemNo = B.FNewMemNo
FROM TMemberSaleBill AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
SELECT * FROM sysobjects WHERE name like '%Member%' and type = 'U'
SELECT * FROM TMemberCoursePack
--<EFBFBD><EFBFBD>Ƭ
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberPhoto AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
AND B.FNewMemId NOT IN(SELECT FMemId FROM TMemberPhoto)
AND B.FMemId NOT IN(4622709038010346916,8272471197083282758,6864468426306491951)
DROP TABLE #Photo
SELECT B.FMemId,B.FNewMemId,A.Ftype,A.FImagePath,A.FChangeId,IDENTITY(INT,1,1)FIndex INTO #Photo FROM TMemberPhoto AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND B.FNewMemId != 0
AND B.FNewMemId NOT IN(SELECT FMemId FROM TMemberPhoto)
ORDER BY FNewMemId
SELECT FNewMemId ,SUM(1),MIN(FMemId) FROM #Photo
GROUP BY FNewMemId
HAVING (SUM(1) ) > 1
DELETE #Photo WHERE FMemId IN(4622709038010346916,8272471197083282758,6864468426306491951)
SELECT * FROM TMember WHERE FNewMemId = 5327350039728720478
--
SELECT * FROM TMemberSaleBill
WHERE FMemId IN(SELECT FMemId FROM TMember WHERE FNewMemId != 0)
SELECT