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/美尚/分离003,sql.sql

153 lines
4.6 KiB

1 year ago
use jinan_jumei
USE JINAN_MEISHANG
SELECT * FROM TCompany
UPDATE TCompany SET FDeleted = 1,FNo = FNo + '<EFBFBD><EFBFBD>ɾ' WHERE FNo = '003'
SELECT * FROM TMemberCard WHERE FCompId = 3472331387795668992
DROP TABLE #Card
--<EFBFBD>п<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>Ŀ<EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>˾
SELECT C.FCardId,C.FCardNo ,C.FCompId AS FOldCompId,CAST(0 AS BIGINT) AS FNewCompId
INTO #Card
FROM TMemberSaleCard AS A,TMemberSaleBill AS B,TMemberCard AS C
WHERE A.FBillId = B.FBilliD
AND B.FState = 1
AND C.FCardId = A.FCardId
AND ((B.FCompId = 3472331387795668992 AND C.FCompId != 3472331387795668992)
OR (B.FCompId != 3472331387795668992 AND C.FCompId = 3472331387795668992))
GROUP BY C.FCardId,C.FCardNo ,C.FCompId
DECLARE @CardId BIGINT
DECLARE @CardNo VARCHAR(300)
DECLARE @OldCompId BIGINT
DECLARE @NewCompId BIGINT
DECLARE List CURSOR FOR
SELECT A.FCardId,A.FOldCompId FROM #Card AS A
OPEN List
FETCH List INTO @CardId,@OldCompId
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT TOP 1 @NewCompId = T.FCompId
FROM TMemberSaleBill AS T,TMemberSaleCard AS B
WHERE T.FBillId = B.FBillId
AND B.FSalePrice > 0
AND B.FCardId = @CardId
ORDER BY T.FBillTime DESC
print @NewCompId
print @OldCompId
IF @OldCompId != @NewCompId
UPDATE #Card SET FNewCompId = @NewCompId WHERE FCardId = @CardId
-- UPDATE TMemberCard SET FCompId = @CompId
FETCH List INTO @CardId,@OldCompId
END
CLOSE List
DEALLOCATE LIST
UPDATE #Card SET FNewCompId = 0
UPDATE A
SET A.FCompId = B.FNewCompId
FROM TMemberCard AS A,#Card AS B
WHERE A.FCardId = B.FCardId
--<EFBFBD><EFBFBD><EFBFBD>»<EFBFBD>Ա<EFBFBD>ŵ<EFBFBD>
SELECT A.FMemId FROM TMemberCard AS A,TMember AS B
WHERE A.FCompId = B.FCompId
AND A.FMemID = B.FMemId
SELECT * FROM #Card WHERE FOldCompID != FNewCompId
UPDATE TMemberCard SET FDeleted = 1,FMemo = FMemo + '<EFBFBD><EFBFBD>2018<EFBFBD><EFBFBD>6<EFBFBD><EFBFBD>һ<EFBFBD>մ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><EFBFBD>',FCardNo = FCardNo + '<EFBFBD><EFBFBD>ɾ'
WHERE FCompId != 3472331387795668992
AND FDeleted = 0
UPDATE TMemberCourse SET FDeleted = 1,FMemo = FMemo + '<EFBFBD><EFBFBD>2018<EFBFBD><EFBFBD>6<EFBFBD><EFBFBD>һ<EFBFBD>մ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><EFBFBD>'
WHERE FCompId != 3472331387795668992
AND FDeleted = 0
UPDATE TMember SET FDeleted = 1,FMemo = FMemo + '<EFBFBD><EFBFBD>2018<EFBFBD><EFBFBD>6<EFBFBD><EFBFBD>һ<EFBFBD>մ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><EFBFBD>' ,FMemNo = FMemNo + '<EFBFBD><EFBFBD>ɾ'
WHERE FMemId NOT IN(SELECT FMemId FROM TMemberCard WHERE FDeleted = 0 UNION ALL SELECT FMemId FROM TMemberCourse WHERE FDeleted = 0)
AND FDeleted = 0
AND (FIsVisitor = 0 OR (FIsVisitor = 1 AND FCompId != 3472331387795668992))
UPDATE TCompany SET FDeleted = 1,FNo =FNo + '<EFBFBD><EFBFBD>ɾ' WHERE FId != 3472331387795668992 AND FId !=0
UPDATE TCompany SET FDeleted = 0,FNo =REPLACE(FNo , '<EFBFBD><EFBFBD>ɾ','') WHERE FId = 1
--ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>006<EFBFBD>ĵ<EFBFBD><EFBFBD><EFBFBD>
UPDATE TMember SET FCompId = 3472331387795668992 WHERE FDeleted = 0
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FCompId = B.FCompId
FROM jinan_meishang..TMemberCard AS A,jinan_jumei..TMemberCard AS B
WHERE A.FCardId = B.FCardId
AND A.FCompId != B.FCompId
UPDATE A
SET A.FCompId = B.FCompID
FROM TMemberCard AS B,TMember AS A
WHERE A.FMemId = B.FMemId
UPDATE jinan_meishang..TMemberCard SET FDeleted = 1,FMemo = FMemo + '<EFBFBD><EFBFBD>2018<EFBFBD><EFBFBD>6<EFBFBD><EFBFBD>һ<EFBFBD>մ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><EFBFBD>',FCardNo = FCardNo + '<EFBFBD><EFBFBD>ɾ'
WHERE FCompId = 3472331387795668992
AND FDeleted = 0
UPDATE jinan_meishang..TMemberCourse SET FDeleted = 1,FMemo = FMemo + '<EFBFBD><EFBFBD>2018<EFBFBD><EFBFBD>6<EFBFBD><EFBFBD>һ<EFBFBD>մ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><EFBFBD>'
WHERE FCompId = 3472331387795668992
AND FDeleted = 0
UPDATE jinan_meishang..TMember SET FDeleted = 1,FMemo = FMemo + '<EFBFBD><EFBFBD>2018<EFBFBD><EFBFBD>6<EFBFBD><EFBFBD>һ<EFBFBD>մ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><EFBFBD>' ,FMemNo = FMemNo + '<EFBFBD><EFBFBD>ɾ'
WHERE FMemId NOT IN(SELECT FMemId FROM jinan_meishang..TMemberCard WHERE FDeleted = 0 UNION ALL SELECT FMemId FROM jinan_meishang..TMemberCourse WHERE FDeleted = 0)
AND FDeleted = 0
AND (FIsVisitor = 0 OR (FIsVisitor = 1 AND FCompId = 3472331387795668992))
DELETE JiNan_MeiShang..TBizLog WHERE FCompId = 3472331387795668992
DELETE JiNan_MeiShang..TBizLogIndex WHERE FLogId NOT IN(SELECT FId FROM JiNan_MeiShang..TBizLog)
DELETE JiNan_JuMei..TBizLog WHERE FCompId != 3472331387795668992
DELETE JiNan_JuMei..TBizLogIndex WHERE FLogId NOT IN(SELECT FId FROM JiNan_JuMei..TBizLog)
DELETE JiNan_MeiShang..TLoginSession WHERE FCompId = 3472331387795668992
DELETE JiNan_JuMei..TLoginSession WHERE FCompId != 3472331387795668992
DELETE TBizLog WHERE FCompId = 3472331387795668992
DELETE TBizLogIndex WHERE FLogId NOT IN(SELECT FId FROM TBizLog)
PCopyTable 'TBizLog','JINAN_MEISHANG..TBizLog',' AND FCompId = 3472331387795668992 '
SET IDENTITY_INSERT TBizLog OFF
DELETE TItemSub WHERE FCompId NOT IN(SELECT FId FROM TCompany WHERE FDeleted = 0)
DELETE TGoodsSub WHERE FCompId NOT IN(SELECT FId FROM TCompany WHERE FDeleted = 0)
DELETE TEmployeeSub WHERE FCompId NOT IN(SELECT FId FROM TCompany WHERE FDeleted = 0)
DELETE TMemberCardTypeSub WHERE FCompId NOT IN(SELECT FId FROM TCompany WHERE FDeleted = 0)