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/分离门店.sql

593 lines
28 KiB

use QingDao_saidao15
-- DongYing_DongHua 是被分离的 jinan_lingxiuat是分离出来的
select * from DongYing_DongHua.dbo.TCompany
CREATE TABLE #Company
(
FCompId BIGINT
)
INSERT #Company
SELECT FId FROM DongYing_DongHua.dbo.TCompany WHERE FNo = '010'
UPDATE TCompany SET FNo = '000' WHERE FNo = '001'
--门店资料
EXEC PCopyTable 'TCompany','DongYing_DongHua.dbo.TCompany',' AND FId IN(SELECT FCompId FROM #Company)'
EXEC PCreateCompanyTree
--权限字典
EXEC PCopyTable 'TAccessDict','DongYing_DongHua.dbo.TAccessDict',' AND FKey IN(SELECT FKey FROM DongYing_DongHua.dbo.TAccessDict) AND FKey NOT IN(SELECT FKey FROM TAccessDict)'
--用户
DROP TABLE #User
SELECT * INTO #User FROM DongYing_DongHua.dbo.TUser
WHERE 1=1
AND FId IN(SELECT FUserId FROM DongYing_DongHua.dbo.TUserAllowCompany WHERE FCompId IN( SELECT FCompId FROM #Company))
UPDATE #User SET FNo = 'FT' + FNo WHERE FNo IN(SELECT FNo FROM TUser)
EXEC PCopyTable 'TUser','#User',''
EXEC PCopyTable 'TRole','DongYing_DongHua.dbo.TRole',' AND FId IN(SELECT FRoleId FROM DongYing_DongHua.dbo.TUserRole WHERE FUserId IN(SELECT FId FROM TUser))'
EXEC PCopyTable 'TUserRole','DongYing_DongHua.dbo.TUserRole',' AND FUserId IN(SELECT FId FROM TUser) '
EXEC PCopyTable 'TRoleAccess','DongYing_DongHua.dbo.TRoleAccess',' AND FRoleId IN(SELECT FId FROM TRole) '
EXEC PCopyTable 'TUserAllowCompany','DongYing_DongHua.dbo.TUserAllowCompany',' AND FCompId IN( SELECT FCompId FROM #Company)'
--基本类别资料
DELETE TBasicTypeSub
DELETE TBasicType
DROP TABLE #BasicType
SELECT * INTO #BasicType FROM DongYing_DongHua.dbo.TBasicType
WHERE 1=1
AND FId IN(SELECT FBasicTypeId FROM DongYing_DongHua.dbo.TBasicTypeSub
WHERE FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company ))
AND FId NOT IN(SELECT FId FROM TBasicType)
SELECT * FROM #BasicType
UPDATE #BasicType SET FNo = 'FT' + FNo WHERE FNo IN(SELECT FNo FROM TBasicType)
EXEC PCopyTable 'TBasicType','#BasicType',' '
SELECT * INTO #BasicTypeSub
FROM DongYing_DongHua.dbo.TBasicTypeSub AS A
WHERE 1=1
AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company)
AND NOT EXISTS(SELECT 1 FROM TBasicTypeSub AS B WHERE A.FBasicTypeId = B.FBasicTypeId AND A.FCompId = B.FCompId)
EXEC PCopyTable 'TBasicTypeSub','#BasicTypeSub',' '
--账户
DELETE TPayAccount
SELECT * INTO #PayAccount
EXEC PCopyTable 'TPayAccount','DongYing_DongHua.dbo.TPayAccount',' '
EXEC PCopyTable 'TPayAccountSub','DongYing_DongHua.dbo.TPayAccountSub',' AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company) '
--基本类别同步
DELETE TBasicDataSyncControl
EXEC PCopyTable 'TBasicDataSyncControl','DongYing_DongHua.dbo.TBasicDataSyncControl',' AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company)'
--员工
DELETE TEmployeeRole WHERE FId > 0
DELETE TEmployeeRolePermission
EXEC PCopyTable 'TEmployeeRole','DongYing_DongHua.dbo.TEmployeeRole',' AND FId > 0 '
EXEC PCopyTable 'TEmployeeRolePermission','DongYing_DongHua.dbo.TEmployeeRolePermission',' '
EXEC PCopyTable 'TEmployee','DongYing_DongHua.dbo.TEmployee',' AND FId IN(SELECT FEmpId FROM DongYing_DongHua.dbo.TEmployeeSub WHERE FCompId IN(SELECT FCompId FROM #Company))'
EXEC PCopyTable 'TEmployeeSub','DongYing_DongHua.dbo.TEmployeeSub',' AND FCompId IN(SELECT FCompId FROM #Company)'
EXEC PCopyTable 'TEmployeeAllowCompany','DongYing_DongHua.dbo.TEmployeeAllowCompany',' AND FEmpId IN(SELECT FId FROM TEmployee) AND FCompId IN(SELECT FCompId FROM #Company)'
EXEC PCopyTable 'TEmployeeExpenses','DongYing_DongHua.dbo.TEmployeeExpenses',' AND FEmpId IN(SELECT FId FROM TEmployee) AND FCompId IN(SELECT FCompId FROM #Company)'
EXEC PCopyTable 'TEmployeeReferral','DongYing_DongHua.dbo.TEmployeeReferral',' AND FEmpId IN(SELECT FId FROM TEmployee) '
--单子上的
EXEC PCopyTable 'TEmployee','DongYing_DongHua.dbo.TEmployee',' AND FId IN(SELECT A.FEmpId FROM DongYing_DongHua.dbo.TConsumeItemEmployee AS A,DongYing_DongHua.dbo.TCOnsumeBill AS B WHERE B.FBillId = A.FBillId AND B.FCompId IN(SELECT FCompId FROM #Company) AND A.FEmpId NOT IN(SELECT FId FROM TEmployee))'
--产品
DELETE TGoods WHERE FId > 0
EXEC PCopyTable 'TGoods','DongYing_DongHua.dbo.TGoods',' '
EXEC PCopyTable 'TGoodsSub','DongYing_DongHua.dbo.TGoodsSub','AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company)'
EXEC PCopyTable 'TGoodsMultiUnit','DongYing_DongHua.dbo.TGoodsMultiUnit','AND FGoodsId In(SELECT FId FROM TGoods)'
--产品提成
EXEC PCopyTable 'TGoodsBaseComm','DongYing_DongHua.dbo.TGoodsBaseComm',' AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company) '
DELETE TGoodsCommSchemeDetail
DELETE TGoodsCommSchemeSection
DELETE TGoodsCommSchemeMaster
EXEC PCopyTable 'TGoodsCommSchemeMaster','DongYing_DongHua.dbo.TGoodsCommSchemeMaster',' AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company) '
EXEC PCopyTable 'TGoodsCommSchemeMaster','DongYing_DongHua.dbo.TGoodsCommSchemeMaster',' AND FId=0 '
EXEC PCopyTable 'TGoodsCommSchemeSection','DongYing_DongHua.dbo.TGoodsCommSchemeSection',' AND FId = 0 '
EXEC PCopyTable 'TGoodsCommSchemeSection','DongYing_DongHua.dbo.TGoodsCommSchemeSection',' AND FMasterId IN(SELECT FId FROM TGoodsCommSchemeMaster) AND FId != 0 '
EXEC PCopyTable 'TGoodsCommSchemeDetail','DongYing_DongHua.dbo.TGoodsCommSchemeDetail',' AND FMasterId IN(SELECT FId FROM TGoodsCommSchemeMaster) AND FId != 0 '
--产品折扣
EXEC PCopyTable 'TGoodsDiscountMaster','DongYing_DongHua.dbo.TGoodsDiscountMaster',' AND FCompId IN(SELECT FCompId FROM #Company) '
EXEC PCopyTable 'TGoodsDiscountDetail','DongYing_DongHua.dbo.TGoodsDiscountDetail',' AND FMasterId IN(SELECT FId FROM TGoodsDiscountMaster) '
--库存
EXEC PCopyTable 'TInventory','DongYing_DongHua.dbo.TInventory',' AND FCompId IN( SELECT FCompId FROM #Company) '
EXEC PCopyTable 'TInventoryLog','DongYing_DongHua.dbo.TInventoryLog',' AND FCompId IN(SELECT FCompId FROM #Company) '
UPDATE DongYing_DongHua.dbo.TItemSub
SET FAllowBooking = 0
--项目
EXEC PCopyTable 'TItem','DongYing_DongHua.dbo.TItem',' AND FId IN(SELECT FItemId FROM DongYing_DongHua.dbo.TItemSub WHERE FCompId IN(SELECT FCompId FROM #Company))'
EXEC PCopyTable 'TItemSub','DongYing_DongHua.dbo.TItemSub','AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company) AND FItemId IN(SELECT FId FROM TItem)'
--单子上的
EXEC PCopyTable 'TItem','DongYing_DongHua.dbo.TItem',
' AND FId IN(SELECT A.FItemID FROM DongYing_DongHua.dbo.TConsumeItem AS A,DongYing_DongHua.dbo.TCOnsumeBill AS B WHERE B.FBillId = A.FBillId AND B.FCompId IN(SELECT FCompId FROM #Company) AND A.FItemId NOT IN(SELECT FId FROM TItem))'
EXEC PCopyTable 'TItemCostGoods','DongYing_DongHua.dbo.TItemCostGoods','AND FItemId In(SELECT FId FROM TItem)'
EXEC PCopyTable 'TItemFreeGoods','DongYing_DongHua.dbo.TItemFreeGoods','AND FItemId In(SELECT FId FROM TItem)'
--疗程
EXEC PCopyTable 'TCourse','DongYing_DongHua.dbo.TCourse','AND FItemId In(SELECT FId FROM TItem) AND FItemId > 0 AND FId NOT IN(SELECT FId FROM TCourse) '
--项目提成
EXEC PCopyTable 'TItemBaseComm','DongYing_DongHua.dbo.TItemBaseComm',' AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company) '
EXEC PCopyTable 'TItemCommSchemeMaster','DongYing_DongHua.dbo.TItemCommSchemeMaster',' AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company) '
EXEC PCopyTable 'TItemCommSchemeMaster','DongYing_DongHua.dbo.TItemCommSchemeMaster',' AND FId = 0'
EXEC PCopyTable 'TItemCommSchemeSection','DongYing_DongHua.dbo.TItemCommSchemeSection',' AND FId = 0 '
EXEC PCopyTable 'TItemCommSchemeSection','DongYing_DongHua.dbo.TItemCommSchemeSection',' AND FMasterId IN(SELECT FId FROM TItemCommSchemeMaster) AND FId != 0 '
EXEC PCopyTable 'TItemCommSchemeDetail','DongYing_DongHua.dbo.TItemCommSchemeDetail',' AND FMasterId IN(SELECT FId FROM TItemCommSchemeMaster) '
EXEC PCopyTable 'TItemCommSchemeExcept','DongYing_DongHua.dbo.TItemCommSchemeExcept',' AND FMasterId IN(SELECT FId FROM TItemCommSchemeMaster) '
EXEC PCopyTable 'TItemCommSchemeExtra','DongYing_DongHua.dbo.TItemCommSchemeExtra',' AND FMasterId IN(SELECT FId FROM TItemCommSchemeMaster) '
--疗程提成
EXEC PCopyTable 'TCourseSaleBaseComm','DongYing_DongHua.dbo.TCourseSaleBaseComm',' AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company) '
EXEC PCopyTable 'TCourseConsBaseComm','DongYing_DongHua.dbo.TCourseConsBaseComm',' AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company) '
--折扣
EXEC PCopyTable 'TItemDiscountMaster','DongYing_DongHua.dbo.TItemDiscountMaster',' AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company) '
EXEC PCopyTable 'TItemDiscountMid','DongYing_DongHua.dbo.TItemDiscountMid',' AND FParentId IN(SELECT FId FROM TItemDiscountMaster) '
EXEC PCopyTable 'TItemDiscountDetail','DongYing_DongHua.dbo.TItemDiscountDetail',' AND FParentId IN(SELECT FId FROM TItemDiscountMid) '
--卡类别
EXEC PCopyTable 'TMemberCardType','DongYing_DongHua.dbo.TMemberCardType',' AND FId > 9 '
EXEC PCopyTable 'TMemberCardTypeSub','DongYing_DongHua.dbo.TMemberCardTypeSub',' AND FCompId IN( SELECT FCompId FROM #Company)'
EXEC PCopyTable 'TMemberCardTypeAccount','DongYing_DongHua.dbo.TMemberCardTypeAccount',' AND FCardTypeId IN(SELECT FId FROM TMemberCardType)'
EXEC PCopyTable 'TMemberCardTypeFreeItem','DongYing_DongHua.dbo.TMemberCardTypeFreeItem',' AND FCardTypeId IN(SELECT FId FROM TMemberCardType)'
--储值卡提成
EXEC PCopyTable 'TMemberCardTypeBaseComm','DongYing_DongHua.dbo.TMemberCardTypeBaseComm',' AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company) '
--储值卡提成方案
EXEC PCopyTable 'TCardTypeCommSchemeMaster','DongYing_DongHua.dbo.TCardTypeCommSchemeMaster',' AND FCompId IN(SELECT 1 AS FCompId UNION ALL SELECT FCompId FROM #Company) '
EXEC PCopyTable 'TCardTypeCommSchemeSection','DongYing_DongHua.dbo.TCardTypeCommSchemeSection',' AND FId IN(SELECT FId FROM TCardTypeCommSchemeMaster) '
EXEC PCopyTable 'TCardTypeCommSchemeDetail','DongYing_DongHua.dbo.TCardTypeCommSchemeDetail',' AND FId IN(SELECT FId FROM TCardTypeCommSchemeMaster) '
DROP TABLE #Card
DROP TABLE #CardD
DROP TABLE #Course
DROP TABLE #CourseD
DROP TABLE #Member
DELETE TEmployeeSub WHERE FCompId NOT IN(SELECT FId FROM TCompany)
DELETE TCompany WHERE FId > 1
DELETE TCompanyTree WHERE FChildId > 1
DROP TABLE #Card
--会员
SELECT *
INTO #Card
FROM DongYing_DongHua.dbo.TMemberCard WHERE FCompId IN(SELECT FCompId FROM #Company)
--AND FTypeId IN(SELECT FId FROM TMemberCardType WHERE FNo IN('001','208','202','203','204','207','206','205','210','209'))
SELECT * INTO #Course
FROM DongYing_DongHua.dbo.TMemberCourse
WHERE FCompId IN(SELECT FCompId FROM #Company)
--AND FPurchaseDate < '2019-08-04'
--跨点的会员,需要删除
SELECT *
INTO #CardD
FROM DongYing_DongHua.dbo.TMemberCard
WHERE FCardId NOT IN(SELECT FCardId FROM #Card)
AND (FCardId IN(SELECT A.FCardId
FROM DongYing_DongHua.DBO.TConsumeBill AS B,DongYing_DongHua.DBO.TConsumeItemPayment AS A
WHERE A.FBillId = B.FBillId AND B.FCompId IN(SELECT FCompId FROM #Company) AND A.FCardId > 0 AND B.FMemId > 0
UNION ALL
SELECT A.FCardId
FROM DongYing_DongHua.DBO.TConsumeBill AS B,DongYing_DongHua.DBO.TConsumeGoodsPayment AS A
WHERE A.FBillId = B.FBillId AND B.FCompId IN(SELECT FCompId FROM #Company) AND A.FCardId > 0 AND B.FMemId > 0
UNION ALL
SELECT A.FCardId FROM DongYing_DongHua..TMemberSaleCard AS A,TMemberSaleBill AS T WHERE T.FBillId = A.FBillId AND T.FCompId IN(SELECT FCompId FROM #Company)
UNION ALL
SELECT FCardId FROM DongYing_DongHua..TConsumeBill AS T WHERE T.FCompId IN(SELECT FCompId FROM #Company)
)
)
AND FCardId > 0
SELECT * INTO #CourseD
FROM DongYing_DongHua.dbo.TMemberCourse
WHERE FId NOT IN(SELECT FId FROM #Course)
AND (FId IN(SELECT A.FMemCourseId
FROM DongYing_DongHua.DBO.TConsumeBill AS B,DongYing_DongHua.DBO.TConsumeItem AS A
WHERE A.FBillId = B.FBillId AND B.FCompId IN(SELECT FCompId FROM #Company) AND A.FMemCourseId > 0 AND B.FMemId > 0)
)
SELECT FMemID INTO #Member FROM #Card
UNION ALL
SELECT FMemId FROM #Course
UNION ALL
SELECT FMemId FROM #CourseD
UNION ALL
SELECT FMemId FROM #CardD
GROUP BY FMemId
SELECT FItemId FROM DongYing_DongHua.dbo.TMemberCourse WHERE FMemId IN(SELECT FMemID FROM #Member )
AND FItemId NOT IN(SELECT FId FROM TItem)
GROUP BY FItemId
--没有的项目
EXEC PCopyTable 'TItem','DongYing_DongHua.dbo.TItem',
' AND FId IN(SELECT A.FItemID FROM DongYing_DongHua.dbo.TMemberCourse AS A WHERE A.FMemId IN(SELECT FMemId FROM #Member) AND A.FItemId NOT IN(SELECT FId FROM TItem))'
EXEC PCopyTable 'TCourse','DongYing_DongHua.dbo.TCourse','AND FItemId In(SELECT FId FROM TItem) AND FItemId > 0 AND FId NOT IN(SELECT FId FROM TCourse) '
DELETE TMember
EXEC PInitDefaultVisitor
INSERT #Member
SELECT FMemId FROM DongYing_DongHua.dbo.TMember WHERE FMemId IN(SELECT FMemId FROM DongYing_DongHua.dbo.TConsumeBill WHERE FCompId IN(SELECT FCompId FROM #Company))
AND FMemID not in(select fmemid from #Member)
AND FMemId != 0
TRUNCATE TABLE TMemberTransHistPayment
--
EXEC PCopyTable 'TMember','DongYing_DongHua.dbo.TMember',' AND FMemId IN(SELECT FMemID FROM #Member)'
EXEC PCopyTable 'TMemberCard','DongYing_DongHua.dbo.TMemberCard',' AND FCardId IN(SELECT FCardId FROM #Card UNION ALL SELECT FCardId FROM #CardD) '
EXEC PCopyTable 'TMemberCardAccount','DongYing_DongHua.dbo.TMemberCardAccount',' AND FCardid IN(SELECT FCardId FROM #Card UNION ALL SELECT FCardId FROM #CardD) '
EXEC PCopyTable 'TMemberCardAcctHist','DongYing_DongHua.dbo.TMemberCardAcctHist',' AND FCardId IN(SELECT FCardId FROM #Card UNION ALL SELECT FCardId FROM #CardD) '
EXEC PCopyTable 'TMemberCourse','DongYing_DongHua.dbo.TMemberCourse',' AND FId IN(SELECT FId FROM #Course UNION ALL SELECT FId FROM #CourseD) '
EXEC PCopyTable 'TMemberCourseLog','DongYing_DongHua.dbo.TMemberCourseLog',' AND FCardId IN(SELECT FId FROM #Course UNION ALL SELECT FId FROM #CourseD) '
EXEC PCopyTable 'TMemberEmployee','DongYing_DongHua.dbo.TMemberEmployee',' AND FMemId IN(SELECT FMemID FROM #Member) '
EXEC PCopyTable 'TMemberPhoto','DongYing_DongHua.dbo.TMemberPhoto',' AND FMemId IN(SELECT FMemID FROM #Member) '
EXEC PCopyTable 'TMemberPointHist','DongYing_DongHua.dbo.TMemberPointHist',' AND FMemId IN(SELECT FMemID FROM #Member) '
EXEC PCopyTable 'TMemberTransHist','DongYing_DongHua.dbo.TMemberTransHist',' AND FMemId IN(SELECT FMemID FROM #Member) '
EXEC PCopyTable 'TMemberTransHistPayment','DongYing_DongHua.dbo.TMemberTransHistPayment',' AND FMemId IN(SELECT FMemID FROM #Member) '
EXEC PCopyTable 'TMemberOldTransHist','DongYing_DongHua.dbo.TMemberOldTransHist',' AND FMemId IN(SELECT FMemID FROM #Member) '
EXEC PCopyTable 'TMemberCardOldAcctHist','DongYing_DongHua.dbo.TMemberCardOldAcctHist',' AND FMemId IN(SELECT FMemID FROM #Member) '
EXEC PCopyTable 'TMemberChangeLog','DongYing_DongHua.dbo.TMemberChangeLog',' AND FMemId IN(SELECT FMemID FROM #Member) '
EXEC PCopyTable 'TMemberArrear','DongYing_DongHua.dbo.TMemberArrear',' AND FMemId IN(SELECT FMemID FROM #Member)'
EXEC PCopyTable 'TMemberRepay','DongYing_DongHua.dbo.TMemberRepay',' AND FMemId IN(SELECT FMemID FROM #Member) '
EXEC PCopyTable 'TMemberArrearEmployee','DongYing_DongHua.dbo.TMemberArrearEmployee',' AND FMemId IN(SELECT FMemID FROM #Member) '
UPDATE DongYing_DongHua.dbo.TMemberRepay SET FCreatorId = 0 WHERE FCreatorId IS NULL
EXEC PClearMemberData
PClearBill
--开卡
EXEC PCopyTable 'TMemberSaleBill','DongYing_DongHua.dbo.TMemberSaleBill',' AND FCompId IN(SELECT FCompId FROM #Company) '
EXEC PCopyTable 'TMemberSaleCard','DongYing_DongHua.dbo.TMemberSaleCard',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) '
EXEC PCopyTable 'TMemberSaleCourse','DongYing_DongHua.dbo.TMemberSaleCourse',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) '
EXEC PCopyTable 'TMemberSaleCourseGoods','DongYing_DongHua.dbo.TMemberSaleCourseGoods',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) '
EXEC PCopyTable 'TMemberSaleCoursePack','DongYing_DongHua.dbo.TMemberSaleCoursePack',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) '
EXEC PCopyTable 'TMemberSaleDetailSplit','DongYing_DongHua.dbo.TMemberSaleDetailSplit',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) '
EXEC PCopyTable 'TMemberSaleDetailPayment','DongYing_DongHua.dbo.TMemberSaleDetailPayment',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) '
EXEC PCopyTable 'TMemberSaleEmployee','DongYing_DongHua.dbo.TMemberSaleEmployee',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) '
EXEC PCopyTable 'TMemberSaleExchange','DongYing_DongHua.dbo.TMemberSaleExchange',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) '
EXEC PCopyTable 'TMemberSaleExchangeSource','DongYing_DongHua.dbo.TMemberSaleExchangeSource',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) '
EXEC PCopyTable 'TMemberSaleFreeItem','DongYing_DongHua.dbo.TMemberSaleFreeItem',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) '
EXEC PCopyTable 'TMemberSaleInfo','DongYing_DongHua.dbo.TMemberSaleInfo',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) '
EXEC PCopyTable 'TMemberSalePayment','DongYing_DongHua.dbo.TMemberSalePayment',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) '
EXEC PCopyTable 'TMemberSaleRepay','DongYing_DongHua.dbo.TMemberSaleRepay',' AND FBillId IN(SELECT FBillId FROM TMemberSaleBill) '
UPDATE A
SET A.FMemId = 0
FROM DongYing_DongHua.dbo.TConsumeBill AS A
WHERE FBillId IN(
SELECT FBillId FROM DongYing_DongHua.dbo.TConsumeBill WHERE FMemId NOT IN(SELECT FMemId FROM TMember)
AND FCompId IN(4911846110257476344))
SELECT * INTO TEmployee# FROM DongYing_DongHua.dbo.TEmployee
WHERE FId IN(
SELECT FEmpId FROM DongYing_DongHua.dbo.TConsumeItemEmployee
WHERE FEmpId NOT IN(SELECT FId FROM TEmployee)
AND FBillId IN(
SELECT FBillId FROM DongYing_DongHua.dbo.TConsumeBill WHERE 1=1
AND FCompId IN(4911846110257476344)
))
drop table
#Bill
SELECT * INTO #Bill FROM DongYing_DongHua.dbo.TConsumeBill WHERE FMemId NOT IN(SELECT FMemId FROM TMember )
AND FCompId IN(SELECT FCompId FROM #Company)
SELECT * FROM DongYing_DongHua.dbo.TConsumeItemPayment WHERE FBillId IN(SELECT FBillId FROM #Bill)
-- SELECT * FROM TMemberCourse WHERE FId = 5854690029186113860
SELECT * FROM #Bill
-- SELECT * FROM DongYing_DongHua.dbo.TConsumeBill WHERE FBillId = 4666036475072189530
-- SELECT * FROM DongYing_DongHua.dbo.TConsumeItem WHERE FBillId = 4666036475072189530
-- SELECT * FROM DongYing_DongHua.dbo.TMember WHERE FMemId = 5063591074812862030
-- SELECT * FROM DongYing_DongHua.dbo.TConsumeItemPayment WHERE FBillId = 5587125213496234116
-- SELECT * FROM TMemberCard WHERE FCardId = 6363360970883769530
-- SELECT * FROM DongYing_DongHua.dbo.TConsumeBill WHERE FCompId IN(SELECT FCompId FROM #Company)
-- AND FMemId NOT IN(SELECT FMemId FROM TMember)
-- SELECT * FROM DongYing_DongHua.dbo.TMember WHERE FMemId = 8657861351252903685
-- SELECT * FROM DongYing_DongHua.dbo.TMemberCard WHERE FMemId = 8657861351252903685
-- SELECT * FROM #Member WHERE FMemId = 8657861351252903685
INSERT TConsumeItem(FId,FBillId,FSequence,FItemId,FOrigPrice,FVipPrice,FDiscount,FDctPrice,FQuantity,FAmount,FMemCourseId,FMemComboItemId,FUseFreeCourse,FDeptId,FPoint)
SELECT FId,FBillId,FSequence,FItemId,FOrigPrice,FVipPrice,FDiscount,FDctPrice,FQuantity,FAmount,FMemCourseId,ISNULL(FMemComboItemId,0),FUseFreeCourse,FDeptId,FPoint FROM DongYing_DongHua.dbo.TConsumeItem WHERE 1=1 AND FBillId IN(SELECT FBillId FROM TConsumeBill)
SELECT * FROM DongYing_DongHua.dbo.TConsumeBill WHERE FCompId IN(SELECT FCompId FROM #Company)
AND FMemId not IN(SELECT FMemId FROM TMember)
UPDATE DongYing_DongHua.dbo.TConsumeItem SET FMemCombItemId = 0 WHERE FMemCombItemId IS NULL
ALTER TABLE TConsumeItem DROP COLUMN FMemComboItemId
--消费
EXEC PCopyTable 'TConsumeBill','DongYing_DongHua.dbo.TConsumeBill',' AND FCompId IN(SELECT FCompId FROM #Company) '
EXEC PCopyTable 'TConsumeItem','DongYing_DongHua.dbo.TConsumeItem',' AND FBillId IN(SELECT FBillId FROM TConsumeBill) '
EXEC PCopyTable 'TConsumeItemPayment','DongYing_DongHua.dbo.TConsumeItemPayment',' AND FBillId IN(SELECT FBillId FROM TConsumeBill) '
EXEC PCopyTable 'TConsumeItemEmployee','DongYing_DongHua.dbo.TConsumeItemEmployee',' AND FBillId IN(SELECT FBillId FROM TConsumeBill) '
EXEC PCopyTable 'TConsumeGoods','DongYing_DongHua.dbo.TConsumeGoods',' AND FBillId IN(SELECT FBillId FROM TConsumeBill) '
EXEC PCopyTable 'TConsumeGoodsEmployee','DongYing_DongHua.dbo.TConsumeGoodsEmployee',' AND FBillId IN(SELECT FBillId FROM TConsumeBill) '
EXEC PCopyTable 'TConsumeGoodsPayment','DongYing_DongHua.dbo.TConsumeGoodsPayment',' AND FBillId IN(SELECT FBillId FROM TConsumeBill) '
EXEC PCopyTable 'TConsumeItemCostGoods','DongYing_DongHua.dbo.TConsumeItemCostGoods',' AND FBillId IN(SELECT FBillId FROM TConsumeBill) '
UPDATE DongYing_DongHua.dbo.TConsumeItem SET FMemComboItemId = 0 WHERE FMemComboItemId IS NULL
--删除
UPDATE TMemberCard SET FDeleted = 1,FCardnO = FCardNo + '【0531BaQu删除】',FMemo = FMemo + '【0531BaQu删除】'
WHERE FCardId NOT IN(SELECT FCardId FROM #Card)
AND FDeleted = 0
AND FMemID > 0
UPDATE TMemberCourse SET FDeleted = 1,FMemo = FMemo + '【0531BaQu删除】'
WHERE FId NOT IN(SELECT FId FROM #Course)
AND FDeleted = 0
AND FMemID > 0
--删除
UPDATE TMember SET FDeleted = 1,FMemNo = FMemNo + '【0531BaQu删除】',FMemo = FMemo + '【0531BaQu删除】'
WHERE FCompId NOT IN(SELECT FCompId FROM #Company)
AND FMemID NOT IN(SELECT FMemId FROM TMemberCard WHERE FDeleted = 0)
AND FMemID NOT IN(SELECT FMemId FROM TMemberCourse WHERE FDeleted = 0)
AND FMemID > 0
--老店
--删除
UPDATE DongYing_DongHua.dbo.TMemberCard SET FDeleted = 1,FCardnO = FCardNo + '【0531XIDU删除】',FMemo = FMemo + '【0531XIDU删除】'
WHERE FCardId IN(SELECT FCardId FROM #card)
AND FDeleted = 0
SELECT * FROM DongYing_DongHua.dbo.TMemberCard WHERE FCardId IN(SELECT FCardId FROM #MEMBER)
UPDATE DongYing_DongHua.dbo.TMemberCourse SET FDeleted = 1,FMemo = FMemo + '【0531XIDU删除】'
WHERE FId IN(SELECT FId FROM #Course)
AND FDeleted = 0
--删除
UPDATE DongYing_DongHua.dbo.TMember SET FDeleted = 1,FMemNo = FMemNo + '【0531XIDU删除】',FMemo = FMemo + '【0531XIDU删除】'
WHERE FCompId IN(SELECT FCompId FROM #Company)
AND FMemID NOT IN(SELECT FMemId FROM DongYing_DongHua.dbo.TMemberCard WHERE FDeleted = 0)
AND FMemID NOT IN(SELECT FMemId FROM DongYing_DongHua.dbo.TMemberCourse WHERE FDeleted = 0)
AND FDeleted = 0
SELECT * FROM TMember
WHERE LEN(FMemNO) > 20
AND FDeleted = 1
UPDATE A
SET A.FMemNO = B.FMemNo
FROM TConsumeBill AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND A.FMemId> 0
AND B.FDeleted = 1
UPDATE A
SET A.FCardNO = B.FCardNO
FROM TConsumeBill AS A,TMemberCard AS B
WHERE A.FCardId = B.FCardId
AND A.FMemId> 0
AND B.FDeleted = 1
UPDATE A
SET A.FMemNo = B.FMemNo
FROM TMemberSaleBill AS A,TMember AS B
WHERE A.FMemId = B.FMemId
AND A.FMemId> 0
AND B.FDeleted = 1
UPDATE A
SET A.FPayCardno = B.FCardno
FROM TMemberSaleBill AS A,TMemberCard AS B
WHERE A.FPayCardId = B.FCardId
AND A.FPayCardId> 0
AND B.FDeleted = 1
UPDATE A
SET A.FMemNO = B.FMemNo
FROM DongYing_DongHua.dbo.TConsumeBill AS A,DongYing_DongHua.dbo.TMember AS B
WHERE A.FMemId = B.FMemId
AND A.FMemId> 0
AND B.FDeleted = 1
UPDATE A
SET A.FCardNO = B.FCardNO
FROM DongYing_DongHua.dbo.TConsumeBill AS A,DongYing_DongHua.dbo.TMemberCard AS B
WHERE A.FCardId = B.FCardId
AND A.FMemId> 0
AND B.FDeleted = 1
UPDATE A
SET A.FMemNo = B.FMemNo
FROM DongYing_DongHua.dbo.TMemberSaleBill AS A,DongYing_DongHua.dbo.TMember AS B
WHERE A.FMemId = B.FMemId
AND A.FMemId> 0
AND B.FDeleted = 1
UPDATE A
SET A.FPayCardno = B.FCardno
FROM DongYing_DongHua.dbo.TMemberSaleBill AS A,DongYing_DongHua.dbo.TMemberCard AS B
WHERE A.FPayCardId = B.FCardId
AND A.FPayCardId> 0
AND B.FDeleted = 1
--预约
EXEC PCopyTable 'TBooking','DongYing_DongHua.dbo.TBooking',' AND FCompId IN(SELECT FCompId FROM #Company) '
--开单
--没有的项目
EXEC PCopyTable 'TItem','DongYing_DongHua.dbo.TItem',
' AND FId IN(SELECT A.FItemID FROM DongYing_DongHua.dbo.TOrderItem AS A ,TOrderBill AS T WHERE A.FItemId NOT IN(SELECT FId FROM TItem) AND T.FCompId IN(SELECT FCompId FROM #Company))'
EXEC PCopyTable 'TOrderBill','DongYing_DongHua.dbo.TOrderBill',' AND FCompId IN(SELECT FCompId FROM #Company) '
EXEC PCopyTable 'TOrderItem','DongYing_DongHua.dbo.TOrderItem',' AND FBillId IN(SELECT FBillId FROM TOrderBill) '
EXEC PCopyTable 'TOrderGoods','DongYing_DongHua.dbo.TOrderGoods',' AND FBillId IN(SELECT FBillId FROM TOrderBill) '
EXEC PCopyTable 'TOrderItemEmployee','DongYing_DongHua.dbo.TOrderItemEmployee',' AND FBillId IN(SELECT FBillId FROM TOrderBill) '
EXEC PCopyTable 'TOrderGoodsEmployee','DongYing_DongHua.dbo.TOrderGoodsEmployee',' AND FBillId IN(SELECT FBillId FROM TOrderBill) '
--开支
EXEC PCopyTable 'TOtherIncomeBill','DongYing_DongHua.dbo.TOtherIncomeBill',' AND FCompId IN(SELECT FCompId FROM #Company) '
EXEC PCopyTable 'TOtherIncomeDetail','DongYing_DongHua.dbo.TOtherIncomeDetail',' AND FBillId IN(SELECT FBillId FROM TOtherIncomeBill) '
EXEC PCopyTable 'TOtherIncomePayment','DongYing_DongHua.dbo.TOtherIncomePayment',' AND FBillId IN(SELECT FBillId FROM TOtherIncomeBill) '
EXEC PCopyTable 'TExpensesBill','DongYing_DongHua.dbo.TExpensesBill',' AND FCompId IN(SELECT FCompId FROM #Company) '
EXEC PCopyTable 'TExpensesDetail','DongYing_DongHua.dbo.TExpensesDetail',' AND FBillId IN(SELECT FBillId FROM TExpensesBill) '
EXEC PCopyTable 'TExpensesPayment','DongYing_DongHua.dbo.TExpensesPayment',' AND FBillId IN(SELECT FBillId FROM TExpensesBill) '
--入库单
EXEC PCopyTable 'TStockInBill','DongYing_DongHua.dbo.TStockInBill',' AND FCompId IN(SELECT FCompId FROM #Company) '
EXEC PCopyTable 'TStockInDetail','DongYing_DongHua.dbo.TStockInDetail',' AND FBillId IN(SELECT FBillId FROM TStockInBill) '
--出库单
EXEC PCopyTable 'TStockOutBill','DongYing_DongHua.dbo.TStockOutBill',' AND FCompId IN(SELECT FCompId FROM #Company) '
EXEC PCopyTable 'TStockOutDetail','DongYing_DongHua.dbo.TStockOutDetail',' AND FBillId IN(SELECT FBillId FROM TStockOutBill) '
EXEC PCopyTable 'TStockOutDetailBatch','DongYing_DongHua.dbo.TStockOutDetailBatch',' AND FBillId IN(SELECT FBillId FROM TStockOutBill) '
--盘点
EXEC PCopyTable 'TTakeStockBill','DongYing_DongHua.dbo.TTakeStockBill',' AND FCompId IN(SELECT FCompId FROM #Company) '
EXEC PCopyTable 'TTakeStockDetail','DongYing_DongHua.dbo.TTakeStockDetail',' AND FBillId IN(SELECT FBillId FROM TTakeStockBill) '
EXEC PCopyTable 'TTakeStockDetailBatch','DongYing_DongHua.dbo.TTakeStockDetailBatch',' AND FBillId IN(SELECT FBillId FROM TTakeStockBill) '
--日志
ALTER TABLE TBizLog ADD FOldId INT
INSERT TBizLog(FOldId,FTime,FCompId,FCompNo,FUserId,FUserNo,FUserName,FFunction,FOperation,FDescription,FContentType,FContent,FIPAddress,FMachineCode,FVersion)
SELECT FId,FTime,FCompId,FCompNo,FUserId,FUserNo,FUserName,FFunction,FOperation,FDescription,FContentType,FContent,FIPAddress,FMachineCode,FVersion
FROM DongYing_DongHua.dbo.TBizLog
WHERE FCompId IN(SELECT FCompId FROM #Company)
INSERT TBizLogIndex(FLogId,FKey,FValue)
SELECT A.FId,B.FKey,B.FValue
FROM TBizLog AS A,DongYing_DongHua.dbo.TBizLogIndex AS B
WHERE A.FOldId = B.FLogId
EXEC PChangeCenterCompany '007'
COMMIT TRAN
DELETE TCompanyTree
DELETE TCompany WHERE FNo = '001'1
UPDATE TCompany SET FNo = '001' WHERE FNo = '007'
EXEC PCreateCompanyTree
UPDATE TItem SET FDeleted =1,FNo = FNo + '导入删除',FNoOFPad = FNoOFPad +'导入删除'
WHERE FId NOT IN(SELECT FItemId FROM TItemSub)
AND FID NOT IN(SELECT FItemID FROM TConsumeItem)
AND FDeleted = 0
SELECT * FROM TItemSub
DELETE TItemSub WHERE FCompId NOT IN(SELECT FId FROM TCompany)
DELETE TGoodsSub WHERE FCompId NOT IN(SELECT FId FROM TCompany)
UPDATE DongYing_DongHua.dbo.TCompany SET FNo = FNo + '已分离',FDeleted = 1 WHERE FDeleted = 0 AND FId IN(SELECT FCompId FROM #Company)
SELECT * FROM DongYing_DongHua.dbo.TCompany