1、通过导出数据把分公司的配方数据先传到总厂,两个辅助表为schemaAdd和schemadetailAdd.
2、然后运行脚本如下,把数据导入到真实的配方表中。
insert into dbo.TBL_Schema([BranchPKId],[SchemaNo], [SchemaColorNo],
[ModelMakeDate], [Weight], [NetWeight],
[Price], [PantoneNo], [Color],
-- [PriceClass],
[LightSource], [Plastic], [Using], [IsColorModelMade],
[DevelopType], [HasOrder], [Maker], [CustName], [Memo],
[IsConfirmed], [BranchNo], [Operator], [OperateDate], [IsOffline] )
select [PKId], [SchemaNo], [SchemaColorNo],
[ModelMakeDate], [Weight], [NetWeight],
[Price], [PantoneNo], [Color],
-- [PriceClass],
[LightSource], [Plastic], [Using], [IsColorModelMade],
[DevelopType], [HasOrder], [Maker], [CustName], [Memo],
[IsConfirmed], [BranchNo], [Operator], [OperateDate], [IsOffline] FROM dbo.schemaAdd
WHERE PKID NOT IN (SELECT dbo.schemaAdd.PKId
from dbo.schemaAdd,dbo.TBL_Schema
where dbo.TBL_Schema.BranchPKId = dbo.schemaAdd.PKId and dbo.TBL_Schema.BranchNo = dbo.Schemaadd.BranchNo)
insert into dbo.TBL_SchemaDetail ([BranchPKId],[SchemaNo], [BranchNo],
[MaterialNo], [MaterialWeight], [CurMoney],
[IsAppend], [MaterialMemo], [Operator],
[OperateDate], [IsOffline])
select [PKId], [SchemaNo], [BranchNo],
[MaterialNo], [MaterialWeight], [CurMoney],
[IsAppend], [MaterialMemo], [Operator],
[OperateDate], [IsOffline]
FROM dbo.schemadetailAdd
WHERE PKID NOT IN (SELECT schemadetailAdd.PKId
from dbo.schemadetailAdd,dbo.TBL_SchemaDetail
where dbo.TBL_SchemaDetail.BranchPKId = schemadetailAdd.PKId
and dbo.TBL_SchemaDetail.BranchNo = schemadetailAdd.BranchNo)
3、两个表中都有辅助的字段BranchPKId是用作与分公司表中的PKId作对应用的。
4 、
(1)删除配方中的重复项
SELECT *
FROM TBL_SchemaDetail
WHERE (SchemaNo IN
(SELECT SchemaNo
FROM TBL_Schema
GROUP BY schemano
HAVING COUNT(*) > 1)) AND (BranchPKId > 0)
(2)(1)删除配方明细中的重复项
SELECT *
FROM TBL_SchemaDetail
WHERE (SchemaNo IN
(SELECT SchemaNo
FROM TBL_Schema
GROUP BY schemano
HAVING COUNT(*) > 1)) AND (BranchPKId > 0)