DROP TABLE #Company SELECT FId AS FCompId INTO #Company FROM TCompany WHERE FNo IN('005','006','007') SELECT * FROM TMember WHERE FDeleted = 0 AND FMemId IN(SELECT FMemId FROM TMemberCard WHERE FDeleted = 1) SELECT * FROM TMemberCard WHERE FMemId = 9081333813291210871 SELECT * FROM TCompany WHERE FId = 3472330288284041216 SELECT * FROM TCompany SELECT * FROM TMemberCard SELECT * FROM TMember WHERE FCompID = 1 UPDATE TCompany SET FNo = FNo + '已删' ,FDeleted = 1 WHERE FId IN(SELECT FCompId FROM #Company) --删除储值卡 UPDATE TMemberCard SET FCardNo = FCardNo + '已删' ,FDeleted = 1 WHERE FCompId IN(SELECT FCompId FROM #Company) --删除疗程 UPDATE TMemberCourse SET FDeleted = 1 WHERE FCompId IN(SELECT FCompId FROM #Company) --把散客删掉 UPDATE TMember SET FMemNo = FMemNO + '已删' ,FDeleted = 1 WHERE FCompId IN(SELECT FCompId FROM #Company) AND FIsVisitor = 1 --把没有卡资料的会员删掉 UPDATE TMember SET FMemNo = FMemNO + '已删' ,FDeleted = 1 WHERE FCompId IN(SELECT FCompId FROM #Company) AND FMemId NOT IN(SELECT FMemId FROM TMemberCard WHERE FDeleted = 0 UNION ALL SELECT FMemId FROM TMemberCourse WHERE FDeleted = 0 ) AND FIsVisitor = 0 --更新会员的归属门店 UPDATE A SET A.FCompId = B.FCompId FROM TMember AS A,TMemberCard AS B WHERE A.FCompId IN(SELECT FCompId FROM #Company) AND A.FDeleted = 0 AND B.FDeleted = 0 AND A.FMemId = B.FMemId UPDATE A SET A.FCompId = B.FCompId FROM TMember AS A,TMemberCourse AS B WHERE A.FCompId IN(SELECT FCompId FROM #Company) AND A.FDeleted = 0 AND B.FDeleted = 0 AND A.FMemId = B.FMemId --更新单子上的编号 UPDATE A SET A.FMemNO = B.FMemNo FROM TCOnsumeBill AS A,TMember AS B WHERE A.FMemId = B.FMemId AND B.FDeleted = 1 --更新单子上的编号 UPDATE A SET A.FCardNo = B.FCardNo FROM TCOnsumeBill AS A,TMemberCard AS B WHERE A.FCardId = B.FCardId AND B.FDeleted = 1 --更新单子上的编号 UPDATE A SET A.FMemNO = B.FMemNo FROM TMemberSaleBill AS A,TMember AS B WHERE A.FMemId = B.FMemId AND B.FDeleted = 1 --更新单子上的编号 UPDATE A SET A.FPayCardNo = B.FCardNo FROM TMemberSaleBill AS A,TMemberCard AS B WHERE A.FPayCardId = B.FCardId AND B.FDeleted = 1 --更新单子上的编号 UPDATE A SET A.FCardNo = B.FCardNo FROM TMemberSaleCard AS A,TMemberCard AS B WHERE A.FCardId = B.FCardId AND B.FDeleted = 1 --用户 DELETE TUserAllowCompany WHERE FCompId IN(SELECT FCompId FROM #Company) UPDATE TUser SET FNo = FNo + '已删',FDeleted = 1 WHERE FId NOT IN(SELECT FUserId FROM TUserAllowCompany) AND FNo != 'Admin' --项目 DELETE TItemSub WHERE FCompId IN(SELECT FCompId FROM #Company) DELETE TGoodsSub WHERE FCompId IN(SELECT FCompId FROM #Company) DELETE TEmployeeSub WHERE FCompId IN(SELECT FCompId FROM #Company) DELETE TMemberCardTypeSub WHERE FCompId IN(SELECT FCompId FROM #Company) DELETE TBasicTypeSub WHERE FCompId IN(SELECT FCompId FROM #Company) UPDATE TUser SET FDeleted = 0,FNo ='Admin' WHERE FId = 1 DELETE TUserRole WHERE FUserId NOT IN(SELECT FId FROM TUser WHERE FDeleted = 0) DELETE TRole WHERE FId NOT IN(SELECT FRoleId FROM TUserRole) DELETE TRoleAccess WHERE FRoleId NOT IN(SELECT FRoleId FROM TUserRole) UPDATE TItem SET FNo = FNo + '已删',FDeleted = 1 WHERE FId NOT IN( SELECT FItemId FROM TItemSub WHERE FCompId != 1 ) SELECT * FROM TWebAppInfo