(MachSetupTime+(Case when MachRunFactor=0 then 0 else (Case when FactorUnit_DB='1' then D.LotSize/MachRunFactor when FactorUnit_DB='2' then D.LotSize*MachRunFactor
when FactorUnit_DB='3' then MachRunFactor end) end)/(Efficiency/100)) as TimeRequired,0,Efficiency,Remark ,D.LotSize,0,0,0,0
,(Case when dbo.Get_WorkCenter_TypeDB(T.Site,WorkCenterNo)='O' then 'Y' else 'N' end) as OutWorkFlag,WX_PartNo as OutWorkPartNo,0.0 as QtyOnPR,0.0 as QtyOnPO,0.0 as QtyScrapt,Crewsize
,Isnull((Select Max(D.ItemNo) as PreItemNo from RoutingDetail as D Where D.Site=T.Site and D.PartNo=T.PartNo and D.RevNo=T.RevNo and T.ItemNo>D.ItemNo),0)
,Isnull((Select Min(D.ItemNo) as NextItemNo from RoutingDetail as D Where D.Site=T.Site and D.PartNo=T.PartNo and D.RevNo=T.RevNo and D.ItemNo>T.ItemNo),0)
,'N',0
from RoutingDetail as T, ${tableName} as D
Where D.Site=T.Site
and T.site=#{site} and T.PartNo=#{partNo} and T.RevNo=#{revNo}
</insert>
<insertid="saveNewTool">
Insert into SOTool(Site,OrderNo,ItemNo,ToolID,ToolQty,Remark,CreateDate,CreatedBy)