MES生产日报存储过程
USE [ScreenMonitor]
GO
/****** Object: StoredProcedure [dbo].[ImportProductForDay] Script Date: 04/11/2016 17:31:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--=========================================
--DESCRIPTION: 生产日报
--exec ImportProductForDay
-- =============================================
ALTER PROCEDURE [dbo].[ImportProductForDay]
as
declare @BeginDate varchar(20),@EndDate varchar(20)
set @BeginDate=CONVERT(varchar(10),getdate(),121)+' 08:30:00' --'2014-10-20 08:30:00'
set @EndDate=CONVERT(varchar(19),getdate(),121) --'2014-10-24 20:29:59'
--第一部分,基础数据来源。
if object_id('tempdb..#tmpDispatchOrder') is not null drop table #tmpDispatchOrder
create table #tmpDispatchOrder
(
--RowSeq int identity(1,1),
MO varchar(50),
DispatchNo varchar(50),
DispatchPrior float,
ProductNo varchar(50),
MachineNo varchar(50),
ProcCode varchar(20),
StaCode varchar(10),
currDate varchar(10),
Bc varchar(10),
BcCode varchar(10),
BCBeginTime varchar(19),
BCEndTime varchar(19),
ProductName varchar(2000),
MaterialNo varchar(50),
BatchNo varchar(100),
DispatchNum int,
FactStartDate varchar(20),
FactStopDate varchar(20),
StandCycle decimal(18,2),
StandEmployee int,
SocketNum int,
MoType int,
ClassNum int, --班次计划数
ProductNum int ,
ProductQty int,
GoodNum int,--实际合格数
BadNum int,
WorkTime decimal(18,4),
NoCardTime decimal(18,4),
TestModeTime decimal(18,4),
StopTime decimal(18,4),
PatrolMachineNum int,
AdjustMacNum int,
PolishNum int,
BadRate varchar(100),
BadReason varchar(8000),
StartReading varchar(20),
EndReading varchar(20),
Degreeses int,
MeterRate int,
StrEmpName varchar(8000),
DispatchQty int,
Flag int
)
declare @r_EndDate varchar(19)
--select @r_EndDate = CONVERT(varchar(10),dateadd(day,1,@EndDate),121)+ ' 07:59:59'
insert into #tmpDispatchOrder(MO, DispatchNo, DispatchPrior, ProductNo,MachineNo, ProcCode,StaCode, ProductName, BatchNo, DispatchNum, BadNum, FactStartDate, FactStopDate
, StandCycle, StandEmployee, SocketNum,MoType,DispatchQty,flag)
select distinct a.MO, a.DispatchNo, a.DispatchPrior, a.ItemNo,a.MachineNO,a.ProcCode,b.StaCode,c.ItemName, a.LotNO, a.DispatchQty, 0, convert(char(19),a.ActualStartDate,121), convert(char(19),a.ActualEndDate,121)
, a.StandCycle, c.StandEmployee, case a.SocketNum when 0 then 1 else a.SocketNum end SocketNum ,a.MOType,a.DispatchQty,0
from V_DispatchOrder a
inner join mes_machine b on a.MachineNo=b.MachineNo
left join mes_Item c on a.ItemNo=c.ItemNo
left join mes_MouldDetail d on a.MouldNo=d.MouldNo
left join (select DispatchNo,MaterialNO,BatchNO from MES_Material b where b.ID=(select ID=MAX(ID) from MES_Material
where DispatchNo=b.DispatchNO group by DispatchNO) ) m on a.DispatchNo=m.DispatchNO
where dispatchStatus>0
and ((ActualStartDate between @BeginDate and @EndDate )
OR (ActualEndDate between @BeginDate and @EndDate )
OR (ActualStartDate <= @BeginDate and ActualEndDate >= @EndDate))
if object_id('tempdb..#tmpDispatchBc') is not null drop table #tmpDispatchBc
create table #tmpDispatchBc
(
MO varchar(50),
DispatchNo varchar(50),
DispatchPrior float,
ProductNo varchar(50),
ProcCode varchar(20),
currDate varchar(10),
Bc varchar(10),
BcCode varchar(10),
BCBeginTime varchar(20),
BCEndTime varchar(20),
ProdBeginTime datetime,
ProdEndTime datetime,
CycleTime decimal(10,2),
Flag int
)
if object_id('tempdb..#NoCardTime') is not null drop table #NoCardTime
create table #NoCardTime
(
mo varchar(20),
dispatchno varchar(20),
machineno varchar(520),
currDate varchar(10),
BCCode varchar(10),
Bc varchar(10),
BCBeginTime varchar(20),
BCEndTime varchar(20),
TotalTime decimal(18,4),
NoCardTime decimal(18,4),
StopTime decimal(18,4),
TestModeTime decimal(18,4)
)
declare @t_CurDate varchar(10)
select @t_CurDate = CONVERT(varchar(10),convert(datetime,@BeginDate),121)
while(@t_CurDate<=convert(varchar(10),convert(datetime,@EndDate),121))
begin
--未刷卡停机
insert into #tmpDispatchBc(MO, DispatchNo,DispatchPrior,ProductNo,ProcCode, currDate,Bc, BcCode,BCBeginTime,BCEndTime, Flag )
select MO, DispatchNo,DispatchPrior,ProductNo,ProcCode,@t_CurDate,'白班','AC',@t_CurDate+' 08:00:00',@t_CurDate+' 19:59:59',0
from #tmpDispatchOrder
insert into #NoCardTime(MachineNO, BCCode,Bc,CurrDate,BCBeginTime,BCEndTime, MO, DispatchNO)
select MachineNo, 'BC','晚班', @t_CurDate ,@t_CurDate+' 20:00:00',CONVERT(varchar(10),dateadd(day,1,convert(datetime,@t_CurDate)),121)+' 07:59:59', '', ''
from V_Machine --where (@MachineNo = '' or MachineNO like '%'+@MachineNo+'%')
union
select MachineNo, 'AC','白班', @t_CurDate ,@t_CurDate+' 08:00:00',@t_CurDate+' 19:59:59', '', ''
from V_Machine --where (@MachineNo = '' or MachineNO like '%'+@MachineNo+'%')
insert into #tmpDispatchBc(MO, DispatchNo,DispatchPrior,ProductNo,ProcCode,currDate,Bc, BcCode,BCBeginTime,BCEndTime,Flag)
select MO, DispatchNo,DispatchPrior,ProductNo,ProcCode,@t_CurDate,'晚班','BC',@t_CurDate+' 20:00:00',CONVERT(varchar(10),dateadd(day,1,convert(datetime,@t_CurDate)),121)+' 07:59:59',0
from #tmpDispatchOrder
set @t_CurDate = CONVERT(varchar(10),dateadd(day,1,convert(datetime,@t_CurDate)),121)
end
--如果当前时间是白班,删除晚班的记录,因为还没到晚班
delete from #NoCardTime where BCBeginTime >GETDATE()
delete from #tmpDispatchBc where BCBeginTime >GETDATE()
insert into #tmpDispatchOrder(Mo,MoType,DispatchNo,DispatchPrior,ProductNo,ProductName,MachineNo,ProcCode,StaCode,currDate,Bc,BcCode,StandCycle,SocketNum,MaterialNo,BatchNo,BCBeginTime,BCEndTime,DispatchQty,flag)
select Mo,MoType,DispatchNo,DispatchPrior,ProductNo,ProductName,MachineNo,ProcCode,a.StaCode,currDate,Bc,BcCode,
StandCycle,SocketNum, a.MaterialNO,a.BatchNO,BCBeginTime,BCEndTime,DispatchQty,1
from (
select distinct a.Mo,MoType,a.DispatchNo,a.DispatchPrior,a.ProductNo,b.ProductName,b.MachineNo,b.ProcCode,b.StaCode,a.currDate,a.Bc,c.BcCode,b.StandCycle,SocketNum=b.SocketNum,convert(varchar(19),a.BCBeginTime,121) BCBeginTime,convert(varchar(19),a.BCEndTime,121) BCEndTime
,b.MaterialNO
,b.BatchNO,b.DispatchQty
from #tmpDispatchBc a join MES_BCDetail c on a.BcCode=c.BcCode
inner join #tmpDispatchOrder b on a.DispatchNo=b.DispatchNo and a.DispatchPrior=b.DispatchPrior and a.ProductNo=b.ProductNo) a
order by MachineNo, currDate,bc,DispatchNo desc,ProductNo desc
--更新中间表已经生成的数据
update d set ProductNum = prodqty,
ProductQty=prodqty,
BadNum = badqty,
WorkTime = prodtime,
TestModeTime=TestMouldTime,
d.StopTime = j.StopTime,
PatrolMachineNum=xunjiqty
,polishNum=damoqty,flag=2
from #tmpDispatchOrder d join JM_Interface j on d.dispatchno=j.dispatchno and d.dispatchprior=j.dispatchprior and d.currDate=j.currDate and d.BcCode=j.BcCode
where d.flag=1 -- RowSeq between @row_from and @row_to
--delete from #tmpDispatchOrder_Reach where ProductNum=0 and BadNum=0 and TestModeTime=0.00 and WorkTime=0.00 and StopTime=0.00 and PatrolMachineNum=0 and PolishNum=0
--delete from #tmpDispatchOrder_Reach where StopTime<0.00
--计算班次所有派工单的总时间,停机时间就计算空单的停机时间
update t1 set NoCardTime = isnull(i.NoCardTime,0.0000),totaltime=ISNULL(i.TotalTime,0)
from #NoCardTime t1
left join (select t.MachineNO,CurrDate,BCCode,BCBeginTime,BCEndTime, NoCardTime =(DATEDIFF(ss,BCBeginTime,BCEndTime)+1)/3600.0-Sum(TotalTime),Sum(TotalTime) TotalTime
from (select distinct d.MachineNO, d.BCCode,d.CurrDate,d.dispatchno,d.BCBeginTime,d.BCEndTime,TotalTime=d.WorkTime+isnull(d.StopTime,0)+d.TestModeTime
from #tmpDispatchOrder d
where d.DispatchNO <> '' and d.Flag=2) t
group by t.MachineNO,CurrDate,BCCode,BCBeginTime,BCEndTime
)i on t1.MachineNO = i.MachineNO and t1.CurrDate=i.CurrDate and t1.BCCode=i.BCCode
--更新空单的试模时间
update d set TestModeTime=TestMouldTime,d.StopTime=j.stoptime
from #NoCardTime d join JM_Interface j on d.currDate=j.currDate and d.MachineNO = j.MachineNO and d.BcCode=j.BcCode where d.DispatchNO='' and j.DispatchNO=''
--更新中间表还没有生成的派工单的数据
update d set ProductNum = dbo.FN_GetProdQty(Mo,DispatchNo,ProductNo,ProcCode,DispatchPrior, BCBeginTime,BCEndTime)+dbo.FN_GetAdjustMachineQty(Mo,DispatchNo,ProductNo,DispatchPrior, BCBeginTime, BCEndTime,'',ProcCode),
ProductQty=(dbo.FN_GetProdQty(Mo,DispatchNo,ProductNo,ProcCode,DispatchPrior, '','')+dbo.FN_GetAdjustMachineQty(Mo,DispatchNo,ProductNo,DispatchPrior, '', '','',ProcCode))-dbo.FN_GetBadQty(Mo,DispatchNo,ProductNo,ProcCode,DispatchPrior, '', '')-dbo.FN_GetPatrolMachineOrPolishQty(MO,DispatchNo,ProductNo,ProcCode,DispatchPrior,'', '',2),
BadNum = dbo.FN_GetBadQty(Mo,DispatchNo,ProductNo,ProcCode,DispatchPrior, BCBeginTime, BCEndTime),
AdjustMacNum = dbo.FN_GetAdjustMachineQty(Mo,DispatchNo,ProductNo,DispatchPrior, BCBeginTime, BCEndTime,'',ProcCode),
WorkTime = dbo.FN_GetProductTime(mo,DispatchNo,ProcCode,DispatchPrior,BCBeginTime, BCEndTime),
--TestModeTime=case when MoType=2 then dbo.FN_GetProductTime(mo,DispatchNo,ProcCode,DispatchPrior,BCBeginTime, BCEndTime) else 0 end,
TestModeTime=dbo.FN_GetTestModeTime(Mo,DispatchNo,ProcCode,DispatchPrior,BCBeginTime, BCEndTime),
StopTime = dbo.FN_GetStopTime(Mo,DispatchNo,ProcCode,DispatchPrior, BCBeginTime, BCEndTime),
PatrolMachineNum=dbo.FN_GetPatrolMachineOrPolishQty(MO,DispatchNo,ProductNo,ProcCode,DispatchPrior,BCBeginTime, BCEndTime,2)
,polishNum=dbo.FN_GetPolishQty(MO,DispatchNo,ProductNo,ProcCode,DispatchPrior,BCBeginTime, BCEndTime),flag=2
from #tmpDispatchOrder d
where d.flag=1 and GETDATE() between BCBeginTime and BCEndTime
-- update t1 set totaltime=ISNULL(i.TotalTime,0),TestModeTime=dbo.FN_GetStopReasonTimeByMach2(t1.MachineNO,44, t1.BCBeginTime, t1.BCEndTime), StopTime=dbo.FN_GetStopTimeByMachine2(t1.MachineNO, t1.BCBeginTime, t1.BCEndTime)
-- from #NoCardTime t1
-- left join (select t.MachineNO,CurrDate,BCCode,BCBeginTime,BCEndTime,Sum(TotalTime) TotalTime
-- from (select distinct MachineNO, BCCode,CurrDate,dispatchno,BCBeginTime,BCEndTime, TotalTime=WorkTime+StopTime+TestModeTime
-- from #tmpDispatchOrder
-- where isnull(DispatchNO,'') <> '' and flag=2 and GETDATE() between BCBeginTime and BCEndTime) t
-- group by t.MachineNO,CurrDate,BCCode,BCBeginTime,BCEndTime
-- )i on t1.MachineNO = i.MachineNO and t1.CurrDate=i.CurrDate and t1.BCCode=i.BCCode where GETDATE() between t1.BCBeginTime and t1.BCEndTime
--update #NoCardTime set StopTime=dbo.FN_GetStopTimeByMachine3(MachineNO, BCBeginTime, BCEndTime),TestModeTime=dbo.FN_GetStopReasonTimeByMach(MachineNO,44, BCBeginTime, BCEndTime) where totaltime=0.0000 and GETDATE() between BCBeginTime and BCEndTime
--insert into #tmpDispatchOrder(MachineNO, BCCode,Bc, CurrDate, MO, DispatchNO,NoCardTime,TestModeTime,StopTime,BCBeginTime,BCEndTime,flag) select MachineNO, BCCode,Bc, CurrDate, MO, DispatchNO,12.0000-TotalTime-StopTime-TestModeTime,TestModeTime,StopTime,BCBeginTime,BCEndTime,2 from #NoCardTime
if object_id('tempdb..#tmpDispatchOrder1') is not null drop table #tmpDispatchOrder1
create table #tmpDispatchOrder1
(
RowSeq int identity(1,1),
MO varchar(50),
DispatchNo varchar(50),
DispatchPrior float,
ProductNo varchar(50),
MachineNo varchar(50),
ProcCode varchar(20),
StaCode varchar(10),
currDate varchar(10),
Bc varchar(10),
BcCode varchar(10),
BCBeginTime varchar(19),
BCEndTime varchar(19),
ProductName varchar(2000),
MaterialNo varchar(50),
BatchNo varchar(100),
DispatchNum int,
FactStartDate varchar(20),
FactStopDate varchar(20),
StandCycle decimal(18,2),
StandEmployee int,
SocketNum int,
MoType int,
ClassNum int, --班次计划数
ProductNum int ,
ProductQty int,
GoodNum int,--实际合格数
BadNum int,
WorkTime decimal(18,4),
NoCardTime decimal(18,4),
TestModeTime decimal(18,4),
StopTime decimal(18,4),
PatrolMachineNum int,
AdjustMacNum int,
PolishNum int,
BadRate varchar(100),
BadReason varchar(8000),
StartReading varchar(20),
EndReading varchar(20),
Degreeses int,
MeterRate int,
StrEmpName varchar(8000),
DispatchQty int
)
insert into #tmpDispatchOrder1(MO,DispatchNo,DispatchPrior,ProductNo,MachineNo,ProcCode,StaCode,currDate,Bc,BcCode,BCBeginTime,BCEndTime, ProductName,
MaterialNo,BatchNo,DispatchNum,FactStartDate,FactStopDate,StandCycle,StandEmployee,SocketNum,MoType,ClassNum,ProductNum,ProductQty,
GoodNum,BadNum, WorkTime,NoCardTime,TestModeTime,StopTime,PatrolMachineNum,AdjustMacNum,PolishNum,BadRate,BadReason,StartReading,EndReading,Degreeses,MeterRate,StrEmpName,DispatchQty)
select MO,DispatchNo,DispatchPrior,ProductNo,MachineNo,ProcCode,StaCode,currDate,Bc,BcCode,BCBeginTime,BCEndTime, ProductName,
MaterialNo,BatchNo,DispatchNum,FactStartDate,FactStopDate,StandCycle,StandEmployee,SocketNum,MoType,ClassNum,ProductNum,ProductQty,
GoodNum,BadNum, WorkTime,NoCardTime,TestModeTime,StopTime,PatrolMachineNum,AdjustMacNum,PolishNum,BadRate,BadReason,StartReading,EndReading,Degreeses,MeterRate,StrEmpName,DispatchQty from
#tmpDispatchOrder where Flag=2 order by MachineNo, currDate,bc,DispatchNo desc,ProductNo desc
declare @row_from int, @row_to int
--select @out_total_rows = count(*) from #tmpDispatchOrder1
--execute st_MES_RS_Pages @out_total_rows, @in_pagesize, @in_page, @row_from output, @row_to output
update #tmpDispatchOrder1 set ClassNum=CASE WHEN StandCycle = 0 THEN 0 ELSE Ceiling(CAST((WorkTime+StopTime)*3600/
CONVERT(decimal(18,2), StandCycle) *isnull(SocketNum,1) AS decimal(18,4)))END, ProductQty=ProductQty,ProductNum=ProductNum,GoodNum=ProductNum-BadNum-PatrolMachineNum
--,PatrolMachineNum=case when ProductNum>PatrolMachineNum then PatrolMachineNum else 0 end
--where RowSeq between @row_from and @row_to
update #tmpDispatchOrder1 set BadRate=CASE WHEN ProductNum = 0 THEN '0.00%' ELSE rtrim(ltrim(cast(CAST(BadNum/
CONVERT(decimal(18,2),ProductNum)*100 AS decimal(10,2)) as char)))+'%' END
--where RowSeq between @row_from and @row_to
declare @tMo varchar(20),@tDispatchNo varchar(50),@tDispatchPrior float,@tProductNo varchar(50),@tProcCode varchar(20),@tcurrDate varchar(50),@tBc varchar(20),@BCBeginTime varchar(20),
@BCEndTime varchar(20),@tBeginDate varchar(20), @tEndDate varchar(20),@tBadNum int ,@tBadText varchar(8000),@tProductNum int,@QCBillNoList varchar(8000),
@tEmpID varchar(8000),@tEmpName varchar(8000),@iEmpID varchar(10),@iBadNum int,@iBadText varchar(8000),@iEmpName varchar(50),@iQCBillNO varchar(50),@Machine varchar(50)
declare tmpCur cursor for
select Mo,DispatchNo,DispatchPrior,ProductNo,ProcCode,currDate,BCBeginTime,BCEndTime,bc,MachineNo from #tmpDispatchOrder1 --where RowSeq between @row_from and @row_to
OPEN tmpCur
FETCH next FROM tmpCur INTO @tMo, @tDispatchNo,@tDispatchPrior,@tProductNo,@tProcCode,@tcurrDate,@BCBeginTime,@BCEndTime,@tBc,@Machine
while @@fetch_status=0
begin
select @tBadNum=0,@tProductNum=0,@tBadText='',@tBeginDate='',@tEndDate='',@tEmpID='',@tEmpName='',@QCBillNoList=''
select @tBeginDate=@BCBeginTime,
@tEndDate=@BCEndTime
if object_id('tempdb..#tmpQC') is not null drop table #tmpQC
select a.QCBillNO into #tmpQC
from mes_QC a
join mes_qcdetail q on q.qcbillno=a.qcbillno
left join sys_pubcode p on p.fieldvalue=badreasonid and fieldname='ddl_BadReason'
where a.QCDate BETWEEN @tBeginDate AND @tEndDate
and a.DispatchNo=@tDispatchNo and a.ProcCode=@tProcCode and a.ItemNO=@tProductNo
declare tmpCur2 cursor for
select distinct QCBillNO from #tmpQC
open tmpCur2
fetch next from tmpCur2 into @iQCBillNO
while @@fetch_status=0
begin
set @QCBillNoList=case when @QCBillNoList='' then @QCBillNoList+@iQCBillNO else @QCBillNoList+','+@iQCBillNO end
fetch next from tmpCur2 into @iQCBillNO
end
set @tBadText=(select dbo.FN_GetQCQueryClassType(@QCBillNoList))--Add by zhuss
deallocate tmpCur2
update #tmpDispatchOrder1 set BadReason=@tBadText where DispatchNo=@tDispatchNo and ProductNo=@tProductNo and ProcCode=@tProcCode and currDate=@tcurrDate and Bc=@tBc
update #tmpDispatchOrder1 set StrEmpName=dbo.FN_GetEmpNameByMachineNoAndBc(@Machine,@BCBeginTime,@BCEndTime)
where DispatchNo=@tDispatchNo and ProductNo=@tProductNo and ProcCode=@tProcCode and currDate=@tcurrDate and Bc=@tBc
-- /*2014.9.1 hz 添加开始读数,结束读数,度数,电表倍率字段*/
--declare @StartElecNum varchar(20),@EndElecNum varchar(20),@Tmpcount int,@NoCardcount int
--set @StartElecNum='F'
--set @EndElecNum='F'
--select @Tmpcount=COUNT(*) from MES_ElecDetail a inner join #tmpDispatchBc b on a.MO=b.MO and a.DispatchNo=b.DispatchNo and a.DispatchPrior=b.DispatchPrior
-- and a.ProcCode=b.ProcCode where a.MachineNo=@Machine and InputDate between @BCBeginTime and @BCEndTime
-- if(@Tmpcount >1)
-- begin
-- select top 1 @StartElecNum=ElecNum from MES_ElecDetail a inner join #tmpDispatchBc b on a.MO=b.MO and a.DispatchNo=b.DispatchNo and a.DispatchPrior=b.DispatchPrior
-- and a.ProcCode=b.ProcCode where a.MachineNo=@Machine and InputDate between @BCBeginTime and @BCEndTime order by InputDate
-- select top 1 @EndElecNum=ElecNum from MES_ElecDetail a inner join #tmpDispatchBc b on a.MO=b.MO and a.DispatchNo=b.DispatchNo and a.DispatchPrior=b.DispatchPrior
-- and a.ProcCode=b.ProcCode where a.MachineNo=@Machine and InputDate between @BCBeginTime and @BCEndTime order by InputDate desc
-- end
--else
-- begin
-- select top 1 @StartElecNum=ElecNum from MES_ElecDetail a inner join #tmpDispatchBc b on a.MO=b.MO and a.DispatchNo=b.DispatchNo and a.DispatchPrior=b.DispatchPrior
-- and a.ProcCode=b.ProcCode where a.MachineNo=@Machine and InputDate between @BCBeginTime and @BCEndTime order by InputDate
-- end
--update d set StartReading=@StartElecNum,EndReading=@EndElecNum,Degreeses=case when @StartElecNum<>'F' and @EndElecNum<>'F'
-- then case when (CONVERT(int,@EndElecNum)-CONVERT(int,@StartElecNum))<0
-- then 0 else (CONVERT(int,@EndElecNum)-CONVERT(int,@StartElecNum)) end
-- end,MeterRate=80
-- from #tmpDispatchOrder1 d where MachineNo=@Machine and d.Bc=@tBc and currDate=@tcurrDate
--select @NoCardcount=COUNT(*) from MES_ElecDetail a inner join #NoCardTime b on a.MachineNo=b.machineno where a.MachineNo=@Machine and InputDate between @BCBeginTime and @BCEndTime
--if(@NoCardcount >1)
-- begin
-- select top 1 @StartElecNum=ElecNum from MES_ElecDetail a inner join #NoCardTime b on a.MachineNo=b.machineno where a.MachineNo=@Machine and InputDate between @BCBeginTime and @BCEndTime order by InputDate
-- select top 1 @EndElecNum=ElecNum from MES_ElecDetail a inner join #NoCardTime b on a.MachineNo=b.machineno where a.MachineNo=@Machine and InputDate between @BCBeginTime and @BCEndTime order by InputDate desc
-- end
--else
-- begin
-- print 1
-- select top 1 @StartElecNum=ElecNum from MES_ElecDetail a inner join #NoCardTime b on a.MachineNo=b.machineno where a.MachineNo=@Machine and InputDate between @BCBeginTime and @BCEndTime order by InputDate
-- end
--update d set StartReading=@StartElecNum,EndReading=@EndElecNum,Degreeses=case when @StartElecNum<>'F' and @EndElecNum<>'F'
-- then case when (CONVERT(int,@EndElecNum)-CONVERT(int,@StartElecNum))<0
-- then 0 else (CONVERT(int,@EndElecNum)-CONVERT(int,@StartElecNum)) end
-- end,MeterRate=80
-- from #tmpDispatchOrder1 d where MachineNo=@Machine and d.Bc=@tBc and currDate=@tcurrDate
--update #tmpDispatchOrder1 set StartReading=null,EndReading=null,Degreeses=null,MeterRate=null where MachineNo =@Machine and Bc=@tBc and currDate=@tcurrDate and RowSeq<(select top 1 RowSeq from #tmpDispatchOrder1 where MachineNo =@Machine and Bc=@tBc and currDate=@tcurrDate order by RowSeq desc)
/*2014.9.1 end*/
FETCH next FROM tmpCur INTO @tMo, @tDispatchNo,@tDispatchPrior,@tProductNo,@tProcCode,@tcurrDate,@BCBeginTime,@BCEndTime,@tBc,@Machine
END
CLOSE tmpCur
DEALLOCATE tmpCur
--select ROW_NUMBER() OVER(ORDER BY MachineNo asc ) ID,Bc,StaCode,MachineNo,MO,DispatchNo,ProductNo,ProductName,currDate,MaterialNo,BatchNo,ProductNum,GoodNum,BadNum,
--PolishNum,PatrolMachineNum,WorkTime,NoCardTime,TestModeTime,StopTime,BadRate,BadReason,StartReading,EndReading,Degreeses,MeterRate,StrEmpName
-- from #tmpDispatchOrder1 where RowSeq between @row_from and @row_to
select ROW_NUMBER() OVER(ORDER BY MachineNo asc ) ID,Bc,MachineNo,StrEmpName,ProductNo,ProductName,currDate,DispatchQty,ProductQty,GoodNum,BadNum,BadRate,BadReason,BCBeginTime,BCEndTime
from #tmpDispatchOrder1 --where RowSeq between @row_from and @row_to
--select TotalRows = @out_total_rows
MES生产日报存储过程的更多相关文章
- [转帖]SAP MES生产执行系统解决方案
一.SAP MES概述: SAP公司成立于1972年,总部位于德国,是全球最大的企业管理和协同化商务解决方案供应商.全球第三大独立软件供应商.目前,在全球有120多个国家的超过86,000多家用户正在 ...
- 时光如梭,MES生产制造执行系统上线2周年--->2016.08,发个博客展示一下系统的主要功能!
以下程序是系统当中的主要功能信息,一些相对简单功能就不在此处展示了. 1.模具基础资料Excel导入与模具资料手动更新功能.友情提示:为了避免不必要的麻烦已经将部分信息打码.! 2.配方资料Excel ...
- 蒙牛乳业六厂—第一家MES工厂
在上海西门子工业自动化(SIAS)与蒙牛液态奶事业部以及蒙牛集团信息中心的共同努力下,经过项目组成员1年半时间的具体实施,中国乳品行业第一个真正意义上的生产执行系统MES,于2008年6月在蒙牛乳业集 ...
- 属于自己的MES(一)概念
什么叫MES(生产制造执行系统)? 从几个方面来简单说下: 1.定位 没有MES前的工厂生产模式,公司MRP系统与生产现场之间透过人为方式沟通,使生产现场如同黑箱作业,无法掌握实时正确信息. MES的 ...
- 实施一套MES系统需要多少钱?
在制造业深耕的人都知道MES系统对于企业的重要性.MES生产执行系统是制造业生产现场透明化管理的最佳解决方案,制造业工厂通过实施MES系统可以解决生产计划.排产调度.工艺管理.品质管理.现场数据采集和 ...
- 五金配件行业ERP解决方案
五金行业信息化需求分析 “国内竞争国际化,国际竞争国内化”将是近几年我国五金行业发展的特点,中国作为全球五金制造中心的地位将进一步稳固.随着中国融入全球经济环境进程的加快以及经济实力的快速崛起,中国已 ...
- 42岁大龄程序员的迷茫,看我最新尝鲜.net 5+Dapper搭建的WebAPI框架
42岁大龄程序员的迷茫 我真傻,真的.我单知道雪天是野兽在深山里没有食吃,会到村里来;我不知道春天也会有-- 我真傻,真的.我单知道程序员要活到老学到老,年龄大了要失业;我不知道码农(新型农民工)也会 ...
- 工厂为什么要进行计划排产,APS高级计划排程系统的优势作用是什么?
我们每个人的指挥中心是大脑,大脑对我们身体发出各种各样的指令,不停的告诉我们身体去干什么. 那么,一个制造企业的指挥中心是哪里?工厂每天都会接到各种各样的订单,通过几百上千的工人,使用各种设备来生产. ...
- 电子表格分两级:Excel和WPS是一级,未来5年,75%的人将用二级
你印象中的电子表格软件是哪些? 估计绝大多数人,都认为电子表格软件不就是Excel和WPS吗?顶多再加上永中office么,难道还有其他的电子表格软件不成? 没有错,excel和WPS,还有永中,确实 ...
随机推荐
- android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法
这篇文章介绍了android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法,有需要的朋友可以参考一下 布局文件中的TextView属性 复制代码代码如下: < ...
- js学习总结
转自 http://blog.sina.com.cn/s/blog_75cf5f3201011csu.html 一: 关于基本数据类型在栈内存和堆内存中的关系 基本数据对于栈内存和堆内存是可以复制的, ...
- PhoneGap 安装体验
npm -v #显示版本,检查npm 是否正确安装. npm install express #安装express模块 npm install -g express #加上 -g 启用global安装 ...
- [反汇编练习] 160个CrackMe之007
[反汇编练习] 160个CrackMe之007. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...
- I.MX6 开机 闪红屏
/************************************************************************** * I.MX6 开机 闪红屏 * 说明: * 本 ...
- I.MX6 bq27441 driver porting
/************************************************************************** * I.MX6 bq27441 driver p ...
- uestc 1721 吴神,人类的希望
// 将n个相同的球放进m个盒子 盒子不为空的方法总数// dp[i][j] 表示i个盒子 j个球的方法总数// 递推关系 dp[i][j]=dp[i-1][j-1]+d[i][j-i]// a. i ...
- 关于web中的自适应布局
一.”自适应网页设计”的概念 2010年,Ethan Marcotte提出了“自适应网页设计”(Responsive Web Design)--这个名词,指可以自动识别屏幕宽度.并做出相应调整的网页设 ...
- 利用c#反射实现实体类生成以及数据获取与赋值
转:http://hi.baidu.com/xyd21c/item/391da2fc8fb351c10dd1c8b8 原有的实体类成员逐个赋值与获取的方法弊端: 1.每次对实体类属性进行赋值时,都要检 ...
- MyBatis学习 之 二、SQL语句映射文件(1)resultMap
目录(?)[-] 二SQL语句映射文件1resultMap resultMap idresult constructor association联合 使用select实现联合 使用resultMap实 ...