MES系统的有用存储过程
USE [ChiefmesNEW]
GO
/****** Object: StoredProcedure [dbo].[st_WMS_ImportStockInBill] Script Date: 10/13/2015 17:30:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--exec st_WMS_ImportStockInBill 'in','superadmin'
ALTER proc [dbo].[st_WMS_ImportStockInBill]
(
@in_InOut varchar(5) = 'In',
@in_User varchar(50) = ''
--@in_Msg varchar(2000) = ''
)
as
delete from WMS_StockIn where Flag=1
if(@in_InOut = 'Out')
begin
--truncate table MES_ImportDispatchorder
--select * from
--insert into MES_StockIn(MO,DispatchQty,MachineNO,MouldNO,ItemNO,SocketNum,StaCode,StandCycle,ActualStartDate,ActualEndDate,StartDate,EndDate)
--select MO,DispatchQty,MachineNO,MouldNO,ItemNO,SocketNum,StaCode,StandCycle,ActualStartDate,ActualEndDate,StartDate,EndDate from MES_DispatchOrder
--update MES_StockIn set Flag=1
select 1
end
else if(@in_InOut='In')
begin
declare @AffactRows int , @DelCount int
--update WMS_StockIn set ItemNO = convert(varchar(50),convert(decimal(38,0),convert(float,ItemNO)))
--where CHARINDEX('E+',ItemNO)>0
--or CHARINDEX('e+',ItemNO)>0
select Seq = IDENTITY(int), Date,StockNO,CurrDate,MachineNo,MO,MESBC,EmpBC,Remark,ItemNo,ItemName, InQty,PlusQty,BillType
, SupplyNO, AutoRptSAP,RecordMonth, UserCode as StockMan
into #t_Stock
from WMS_StockIn s join (select distinct UserCode,Name from sys_user) u on s.StockMan=u.Name
select @AffactRows =@@ROWCOUNT
insert into ChiefWMS.dbo.WMS_StockInPortLog(ActionName,ActionRemark,AffactRows,CreateTime,CreateMan)
select '入库','入库导入行数',@AffactRows, GETDATE(), @in_User
select @DelCount = 0
select @DelCount=COUNT(*) from #t_Stock
where isnull(ltrim(rtrim(ItemNO)),'') = '' or CHARINDEX('E+',ItemNO)>0
or CHARINDEX('e+',ItemNO)>0
delete WMS_StockInHis where ImportTime<DATEADD(DAY, -10,GETDATE())
insert into WMS_StockInHis([Date],StockNO,CurrDate, MO, MESBC, EmpBC, Remark, ItemNO
, itemName, InQty, PlusQty, Flag, BillType,SupplyNO, ImportTime, ImportUser,AutoRptSAP)
select [Date],StockNO, Convert(varchar(10),CurrDate,120),MO, MESBC, EmpBC, Remark, ItemNO
, itemName, InQty, PlusQty, Flag, BillType, SupplyNO,GETDATE(), 'superadmin',AutoRptSAP
from WMS_StockIn
truncate table WMS_StockIn
if(@DelCount>0)
begin
declare @IdList varchar(8000)
select @IdList = ''
select @IdList = case when @IdList = '' then CONVERT(varchar(1000),seq) else @IdList+','+CONVERT(varchar(1000),seq) end
from #t_Stock where isnull(ltrim(rtrim(ItemNO)),'') = '' or CHARINDEX('E+',ItemNO)>0
select Flag = 'F', Msg = '导入'+CONVERT(varchar(1000),@AffactRows)+'条,其中第'+@IdList+'物料编码出现异常,请把单元格转为文本'
insert into ChangHongWMS_904.dbo.WMS_StockInPortLog(ActionName,ActionRemark,AffactRows,CreateTime,CreateMan)
select '入库','入库删除编号为空',@DelCount, GETDATE(), @in_User
end
exec ChiefWMS.dbo.st_WMS_BatchImportStockIn @in_User
end----------------------------
----------------------------------------------------------------
USE [ChangHong_612]
GO
/****** Object: UserDefinedFunction [dbo].[FN_GetMaterialInfo] Script Date: 10/12/2015 13:46:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*************
creator: zhuss
create date: 2014.09.25
Module: Public
Remark: 返回3小时内原料信息
B03-850-5# 10024320250001 1.01 2015-10-12 09:14:14.000 0
**************/
ALTER FUNCTION [dbo].[FN_GetMaterialInfo](
@MachineNo varchar(20)
,@DispatchNO varchar(50)
,@DispatchPrior float
,@InspectDate datetime
,@Type int --类型(0:表示返回字符(原料编号1,原料描述1/原料编号2,原料描述2/.....) 1:表示返回字符(原料编号1/原料描述2/.....))
)
returns varchar(8000)
AS
begin
declare @tbMaterialInfo table(seq int identity(1,1),MachineNo varchar(20),MaterialInfo varchar(200))
declare @ReturnMaterialInfo varchar(8000),@TotalTimes int,@m int
declare @i int,@count int
select @ReturnMaterialInfo='',@m=3
select @TotalTimes=@m*3600
--循环查找一天内的加料信息
while (not exists(select * from MES_Material m
where DATEDIFF(ss,m.FeedingTime,@InspectDate)>0
and DATEDIFF(ss,m.FeedingTime,@InspectDate)<@TotalTimes
and MachineNo=@MachineNo and DispatchNO=@DispatchNO
and DispatchPrior=@DispatchPrior
) and @m<=24
)
begin
set @m=@m+3
select @TotalTimes=@m*3600
end
if(@m<=24) /*一天(24小时内)有加料信息*/
begin
if(@Type=0)
begin
insert into @tbMaterialInfo(MachineNo,MaterialInfo)
select distinct MachineNO,m.MaterialNO+'/'+p.FeedGrade+'/'+BatchNO
from MES_Material m
left join MES_MaterialPacket p on m.Supplier=p.SupNO and m.MaterialNO=p.MaterialNO
where DATEDIFF(ss,m.FeedingTime,@InspectDate)>0
and DATEDIFF(ss,m.FeedingTime,@InspectDate)<@TotalTimes
and MachineNo=@MachineNo and DispatchNO=@DispatchNO and DispatchPrior=@DispatchPrior
end
else
begin
insert into @tbMaterialInfo(MachineNo,MaterialInfo)
select distinct MachineNO,p.FeedGrade+'/'+BatchNO
from MES_Material m
left join MES_MaterialPacket p on m.Supplier=p.SupNO and m.MaterialNO=p.MaterialNO
where DATEDIFF(ss,m.FeedingTime,@InspectDate)>0
and DATEDIFF(ss,m.FeedingTime,@InspectDate)<@TotalTimes
and MachineNo=@MachineNo and DispatchNO=@DispatchNO and DispatchPrior=@DispatchPrior
end
end
else /*一天(24小时内)没有该工单的加料信息 取该派工单的第一条加料信息*/
begin
if(@Type=0)
begin
insert into @tbMaterialInfo(MachineNo,MaterialInfo)
select distinct top 1 MachineNO,m.MaterialNO+'/'+p.FeedGrade+'/'+BatchNO
from MES_Material m
left join MES_MaterialPacket p on m.Supplier=p.SupNO and m.MaterialNO=p.MaterialNO
where MachineNo=@MachineNo and DispatchNO=@DispatchNO and DispatchPrior=@DispatchPrior
end
else
begin
insert into @tbMaterialInfo(MachineNo,MaterialInfo)
select distinct top 1 MachineNO,p.FeedGrade+'/'+BatchNO
from MES_Material m
left join MES_MaterialPacket p on m.Supplier=p.SupNO and m.MaterialNO=p.MaterialNO
where MachineNo=@MachineNo and DispatchNO=@DispatchNO and DispatchPrior=@DispatchPrior
end
end
select @count=Count(*),@i=1 from @tbMaterialInfo
while(@i<=@count)
begin
if(@ReturnMaterialInfo='')
select @ReturnMaterialInfo=MaterialInfo from @tbMaterialInfo where seq=@i
else
set @ReturnMaterialInfo=@ReturnMaterialInfo+','+(select MaterialInfo from @tbMaterialInfo where seq=@i)
set @i=@i+1
end
return @ReturnMaterialInfo
end
--------------------------------------------------------------
USE [ChiefmesNEW]
GO
/****** Object: StoredProcedure [dbo].[st_MES_RptInspectFirst] Script Date: 10/12/2015 15:32:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: lxf
-- Create date: 2014.6.30
-- Description: 首检报表
-- st_MES_RptInspectFirst '2015-09-22 08:00:00','2015-10-12 14:15:10','','',''
-- 修改FN_GetSwingCardEmpNameByDis函数调用,添加时间传参 2014.10.28 hz
-- =============================================
ALTER PROCEDURE [dbo].[st_MES_RptInspectFirst]
@StartDate VARCHAR(19),
@EndDate VARCHAR(19),
@ItemNo varchar(50),
@MachineNo varchar(50),
@CheckMan varchar(20)
AS
BEGIN
declare @strSQL nvarchar(4000)
declare @allRecordSQL nvarchar(4000)
declare @strWhere nvarchar(4000)
--建临时表保存品质检验记录
IF object_id('tempdb..#InspectFirst') is not NULL drop table #InspectFirst
CREATE TABLE #InspectFirst
(
ID int ,
BillNO varchar(20),
MO varchar(20) ,
DispatchNo varchar(50),
ActualStartDate datetime,
ActualEndDate datetime,
DispatchPrior float,
ProcCode varchar(20),
StaCode varchar(10),
ItemNO varchar(50) ,
MachineNo varchar(20) ,
WorkMan varchar(2000) ,
CheckMan varchar(20) ,
CheckTime datetime ,
CheckReason varchar(200),
CheckType smallint ,
Remark varchar(200) ,
AbnormalNO varchar(50) ,
WeightSample int ,
OutSample int ,
InkSample int ,
SizeSample int ,
DeformSample int ,
ConfirmMan varchar(20) ,
ConfirmTime datetime ,
CreateMan nvarchar(200) ,
CreateTime datetime ,
UpdateMan nvarchar(200) ,
UpdateTime datetime,
CheckResult varchar(20)
)
set @strWhere=''
set @strSQL='select i.ID ,BillNO ,i.MO ,i.DispatchNo ,d.actualStartDate,d.actualEndDate,i.DispatchPrior ,i.ProcCode ,i.StaCode ,i.ItemNO ,i.MachineNo ,
WorkMan ,i.CheckMan ,CheckTime ,CheckReason ,CheckType ,i.Remark ,AbnormalNO ,WeightSample ,
OutSample ,InkSample ,SizeSample ,DeformSample ,ConfirmMan ,ConfirmTime ,i.CreateMan ,
i.CreateTime ,i.UpdateMan ,i.UpdateTime,CheckResult from MES_Inspect i join mes_dispatchorder d on d.dispatchno=i.dispatchno and d.dispatchprior=i.dispatchprior where checktype=2 '
set @strWhere=@strWhere+' and i.createTime between '''+@StartDate+''' and '''+@EndDate+''''
if @ItemNo<>''
begin
set @strWhere=@strWhere+' and i.itemno like ''%'+@ItemNo+'%'''
end
if @MachineNo<>''
begin
set @strWhere=@strWhere+' and i.machineno like ''%'+@MachineNo+'%'''
end
if @CheckMan<>''
begin
set @strWhere=@strWhere+' and i.createMan like ''%'+@CheckMan+'%'''
end
print @strSQL+@strWhere
insert into #InspectFirst
execute(@strSQL+@strWhere)
update #InspectFirst set WeightSample=(select MAX(WeightSample)from #InspectFirst)
update #InspectFirst set OutSample=(select MAX(OutSample)from #InspectFirst)
update #InspectFirst set InkSample=(select MAX(InkSample)from #InspectFirst)
update #InspectFirst set SizeSample=(select MAX(SizeSample)from #InspectFirst)
update #InspectFirst set DeformSample=(select MAX(DeformSample)from #InspectFirst)
--select * from #InspectFirst
declare @sql varchar(500)
select * from (
select MaterialNO=[dbo].[FN_GetMaterialInfo](c.MachineNo,c.DispatchNo,c.DispatchPrior,w.InspectDate,0)
,c.WeightSample,c.OutSample,c.InkSample,c.SizeSample,c.DeformSample,c.MachineNo,dbo.FN_GetSwingCardEmpNameByDis(c.DispatchNo,c.DispatchPrior,convert(varchar(19),c.CreateTime,120),'') WorkMan,c.AbnormalNO, case when u.Name<>'' then u.Name else u.usercode end CheckMan,c.CheckTime,c.CheckReason,case when u.Name<>'' then u.Name else u.usercode end ConfirmMan,c.Remark,c.CreateTime,i.ItemName,empnamecn CreateMan,w.PartWeight,
case when s.Appearance='' then '-' else s.Appearance end Appearance,case when s.Assembly='' then '-' else s.Assembly end Assembly,case when s.Structure='' then '-' else s.Structure end Structure,
case when s.PerformanceTest3='' then '-' else s.PerformanceTest3 end PerformanceTest3,case when s.PerformanceTest2='' then '-' else s.PerformanceTest2 end PerformanceTest2,case when s.PerformanceTest4='' then '-' else s.PerformanceTest4 end PerformanceTest4,
case when s.PerformanceTest8='' then '-' else s.PerformanceTest8 end PerformanceTest8,case when s.Packing='' then '-' else s.Packing end Packing
,g.LongDownDeformationValue1,g.LongDownDeformationValue2,g.LongDownDeformationValue3,g.LongDownDeformationValue4,g.LongDownDeformationValue5
,g.LongDownGaugeValue1,g.LongDownGaugeValue2,g.LongDownGaugeValue3,g.LongDownGaugeValue4,g.LongDownGaugeValue5
,g.LongMiddleDeformationValue1,g.LongMiddleDeformationValue2,g.LongMiddleDeformationValue3,g.LongMiddleDeformationValue4,g.LongMiddleDeformationValue5
,g.LongMiddleGaugeValue1,g.LongMiddleGaugeValue2,g.LongMiddleGaugeValue3,g.LongMiddleGaugeValue4,g.LongMiddleGaugeValue5
,g.LongUpDeformationValue1,g.LongUpDeformationValue2,g.LongUpDeformationValue3,g.LongUpDeformationValue4,g.LongUpDeformationValue5
,g.LongUpGaugeValue1,g.LongUpGaugeValue2,g.LongUpGaugeValue3,g.LongUpGaugeValue4,g.LongUpGaugeValue5
,g.WidthDownDeformationValue1,g.WidthDownDeformationValue2,g.WidthDownDeformationValue3,g.WidthDownDeformationValue4,g.WidthDownDeformationValue5
,g.WidthDownGaugeValue1,g.WidthDownGaugeValue2,g.WidthDownGaugeValue3,g.WidthDownGaugeValue4,g.WidthDownGaugeValue5
,g.WidthMiddleDeformationValue1,g.WidthMiddleDeformationValue2,g.WidthMiddleDeformationValue3,g.WidthMiddleDeformationValue4,g.WidthMiddleDeformationValue5
,g.WidthMiddleGaugeValue1,g.WidthMiddleGaugeValue2,g.WidthMiddleGaugeValue3,g.WidthMiddleGaugeValue4,g.WidthMiddleGaugeValue5
,g.WidthUpDeformationValue1,g.WidthUpDeformationValue2,g.WidthUpDeformationValue3,g.WidthUpDeformationValue4,g.WidthUpDeformationValue5
,g.WidthUpGaugeValue1,g.WidthUpGaugeValue2,g.WidthUpGaugeValue3,g.WidthUpGaugeValue4,g.WidthUpGaugeValue5
,g.LongUpDeformationResult, g.LongMiddleDeformationResult , g.LongDownDeformationResult , g.WidthUpDeformationResult
, g.WidthMiddleDeformationResult , g.WidthDownDeformationResult
,g.LongUpGaugeResult , g.LongMiddleGaugeResult , g.LongDownGaugeResult , g.WidthUpGaugeResult
, g.WidthMiddleGaugeResult , g.WidthDownGaugeResult
--,case when isnull(g.LongUpDeformationResult,'NG')='OK' and isnull(g.LongMiddleDeformationResult,'NG')='OK' and isnull(g.LongDownDeformationResult,'NG')='OK' and isnull(g.WidthUpDeformationResult,'NG')='OK'
--and isnull(g.WidthMiddleDeformationResult,'NG')='OK' and isnull(g.WidthDownDeformationResult,'NG')='OK' then 'OK' else 'NG' end DeformationResult
--,case when isnull(g.LongUpGaugeResult,'NG')='OK' and isnull(g.LongMiddleGaugeResult,'NG')='OK' and isnull(g.LongDownGaugeResult,'NG')='OK' and isnull(g.WidthUpGaugeResult,'NG')='OK'
--and isnull(g.WidthMiddleGaugeResult,'NG')='OK' and isnull(g.WidthDownGaugeResult,'NG')='OK' then 'OK' else 'NG' end GaugeResult
/*update by zhuss 2014-09-25*/
,DeformationResult=case when ((g.LongUpDeformationResult is null or g.LongUpDeformationResult='') and (g.LongMiddleDeformationResult is null or g.LongMiddleDeformationResult='') and (g.LongDownDeformationResult is null or g.LongDownDeformationResult='')
and (g.WidthUpDeformationResult is null or g.WidthUpDeformationResult='')and (g.WidthMiddleDeformationResult is null or g.WidthMiddleDeformationResult='')
and (g.WidthDownDeformationResult is null or g.WidthDownDeformationResult='')) then '-'
else
case when (isnull(g.LongUpDeformationResult,'OK')='OK' or g.LongUpDeformationResult='') and (isnull(g.LongMiddleDeformationResult,'OK')='OK' or g.LongMiddleDeformationResult='') and (isnull(g.LongDownDeformationResult,'OK')='OK' or g.LongDownDeformationResult='') and
(isnull(g.WidthUpDeformationResult,'OK')='OK' or g.WidthUpDeformationResult='') and (isnull(g.WidthMiddleDeformationResult,'OK')='OK' or g.WidthMiddleDeformationResult='') and (isnull(g.WidthDownDeformationResult,'OK')='OK' or g.WidthDownDeformationResult='') then 'OK' else 'NG' end
end
,GaugeResult= case when((g.LongUpGaugeResult is Null or g.LongUpGaugeResult='') and (g.LongMiddleGaugeResult is Null or g.LongMiddleGaugeResult='') and (g.LongDownGaugeResult is Null or g.LongDownGaugeResult='')
and (g.WidthUpGaugeResult is Null or g.WidthUpGaugeResult='')and (g.WidthMiddleGaugeResult is Null or g.WidthMiddleGaugeResult='')
and (g.WidthDownGaugeResult is Null or g.WidthDownGaugeResult='')) then '-'
else
case when (isnull(g.LongUpGaugeResult,'OK')='OK' or g.LongUpGaugeResult='') and (isnull(g.LongMiddleGaugeResult,'OK')='OK' or g.LongMiddleGaugeResult='') and (isnull(g.LongDownGaugeResult,'OK')='OK' or g.LongDownGaugeResult='')
and (isnull(g.WidthUpGaugeResult,'OK')='OK' or g.WidthUpGaugeResult='') and (isnull(g.WidthMiddleGaugeResult,'OK')='OK' or g.WidthMiddleGaugeResult='') and (isnull(g.WidthDownGaugeResult,'OK')='OK' or g.WidthDownGaugeResult='') then 'OK' else 'NG' end
end
,case when long is not null and longUp is not null then '长:'+cast(long-cast(REPLACE(CAST(longdown as varchar(10)),'-','') as float) as varchar(10)) +'~'+cast(long+longup as varchar(10)) end LongUpDown
,case when Downlong is not null and DownlongUp is not null then '下长:'+cast(Downlong-cast(REPLACE(CAST(Downlongdown as varchar(10)),'-','') as float) as varchar(10)) +'~'+cast(Downlong+Downlongup as varchar(10)) end LongDown
,case when width is not null and widthUp is not null then '宽:'+cast(width-cast(REPLACE(CAST(widthdown as varchar(10)),'-','') as float) as varchar(10))+'~'+cast(width+widthup as varchar(10)) end WidthUpDown
,case when DfLong is not null and DfLongUp is not null then '长:'+cast(DfLong-cast(REPLACE(CAST(DfLongDown as varchar(10)),'-','') as float) as varchar(10))+'~'+cast(DfLong+DfLongup as varchar(10)) end LongDeformationUpDown
,case when Dfwidth is not null and DfWidthUp is not null then '宽:'+cast(Dfwidth-cast(REPLACE(CAST(Dfwidthdown as varchar(10)),'-','') as float) as varchar(10))+'~'+cast(Dfwidth+Dfwidthup as varchar(10)) end WidthDeformationUpDown
,CheckResult
---
,c.DispatchNo,c.DispatchPrior,w.InspectDate
----
--10024320250001
from
#InspectFirst c left join
(select billno,
max(CASE ItemCode WHEN '1' THEN ItemValue END) AS 'Appearance',
max(CASE ItemCode WHEN '2' THEN ItemValue END) AS 'Structure',
max(CASE ItemCode WHEN '3' THEN ItemValue END) AS 'Assembly',
max(CASE ItemCode WHEN '4' THEN ItemValue END) AS 'Packing',
max(CASE ItemCode WHEN '6' THEN ItemValue END) AS 'PerformanceTest3',
max(CASE ItemCode WHEN '5' THEN ItemValue END) AS 'PerformanceTest2',
max(CASE ItemCode WHEN '7' THEN ItemValue END) AS 'PerformanceTest4',
max(CASE ItemCode WHEN '8' THEN ItemValue END) AS 'PerformanceTest8'
from MES_InspectSingle group by billno) s on c.BillNO=s.BillNO left join
(select billno,
max(CASE when ItemType=3 and ItemCode='上长' and Position='长' THEN GaugeValue1 END) AS 'LongUpGaugeValue1',
max(CASE when ItemType=3 and ItemCode='上长' and Position='长' THEN GaugeValue2 END) AS 'LongUpGaugeValue2',
max(CASE when ItemType=3 and ItemCode='上长' and Position='长' THEN GaugeValue3 END) AS 'LongUpGaugeValue3',
max(CASE when ItemType=3 and ItemCode='上长' and Position='长' THEN GaugeValue4 END) AS 'LongUpGaugeValue4',
max(CASE when ItemType=3 and ItemCode='上长' and Position='长' THEN GaugeValue5 END) AS 'LongUpGaugeValue5',
max(CASE when ItemType=3 and ItemCode='中长' and Position='长' THEN GaugeValue1 END) AS 'LongMiddleGaugeValue1',
max(CASE when ItemType=3 and ItemCode='中长' and Position='长' THEN GaugeValue2 END) AS 'LongMiddleGaugeValue2',
max(CASE when ItemType=3 and ItemCode='中长' and Position='长' THEN GaugeValue3 END) AS 'LongMiddleGaugeValue3',
max(CASE when ItemType=3 and ItemCode='中长' and Position='长' THEN GaugeValue4 END) AS 'LongMiddleGaugeValue4',
max(CASE when ItemType=3 and ItemCode='中长' and Position='长' THEN GaugeValue5 END) AS 'LongMiddleGaugeValue5',
max(CASE when ItemType=3 and ItemCode='下长' and Position='长' THEN GaugeValue1 END) AS 'LongDownGaugeValue1',
max(CASE when ItemType=3 and ItemCode='下长' and Position='长' THEN GaugeValue2 END) AS 'LongDownGaugeValue2',
max(CASE when ItemType=3 and ItemCode='下长' and Position='长' THEN GaugeValue3 END) AS 'LongDownGaugeValue3',
max(CASE when ItemType=3 and ItemCode='下长' and Position='长' THEN GaugeValue4 END) AS 'LongDownGaugeValue4',
max(CASE when ItemType=3 and ItemCode='下长' and Position='长' THEN GaugeValue5 END) AS 'LongDownGaugeValue5',
max(CASE when ItemType=3 and ItemCode='左宽' and Position='宽' THEN GaugeValue1 END) AS 'WidthUpGaugeValue1',
max(CASE when ItemType=3 and ItemCode='左宽' and Position='宽' THEN GaugeValue2 END) AS 'WidthUpGaugeValue2',
max(CASE when ItemType=3 and ItemCode='左宽' and Position='宽' THEN GaugeValue3 END) AS 'WidthUpGaugeValue3',
max(CASE when ItemType=3 and ItemCode='左宽' and Position='宽' THEN GaugeValue4 END) AS 'WidthUpGaugeValue4',
max(CASE when ItemType=3 and ItemCode='左宽' and Position='宽' THEN GaugeValue5 END) AS 'WidthUpGaugeValue5',
max(CASE when ItemType=3 and ItemCode='中宽' and Position='宽' THEN GaugeValue1 END) AS 'WidthMiddleGaugeValue1',
max(CASE when ItemType=3 and ItemCode='中宽' and Position='宽' THEN GaugeValue2 END) AS 'WidthMiddleGaugeValue2',
max(CASE when ItemType=3 and ItemCode='中宽' and Position='宽' THEN GaugeValue3 END) AS 'WidthMiddleGaugeValue3',
max(CASE when ItemType=3 and ItemCode='中宽' and Position='宽' THEN GaugeValue4 END) AS 'WidthMiddleGaugeValue4',
max(CASE when ItemType=3 and ItemCode='中宽' and Position='宽' THEN GaugeValue5 END) AS 'WidthMiddleGaugeValue5',
max(CASE when ItemType=3 and ItemCode='右宽' and Position='宽' THEN GaugeValue1 END) AS 'WidthDownGaugeValue1',
max(CASE when ItemType=3 and ItemCode='右宽' and Position='宽' THEN GaugeValue2 END) AS 'WidthDownGaugeValue2',
max(CASE when ItemType=3 and ItemCode='右宽' and Position='宽' THEN GaugeValue3 END) AS 'WidthDownGaugeValue3',
max(CASE when ItemType=3 and ItemCode='右宽' and Position='宽' THEN GaugeValue4 END) AS 'WidthDownGaugeValue4',
max(CASE when ItemType=3 and ItemCode='右宽' and Position='宽' THEN GaugeValue5 END) AS 'WidthDownGaugeValue5',
max(CASE when ItemType=5 and ItemCode='上长' and Position='长' THEN GaugeValue1 END) AS 'LongUpDeformationValue1',
max(CASE when ItemType=5 and ItemCode='上长' and Position='长' THEN GaugeValue2 END) AS 'LongUpDeformationValue2',
max(CASE when ItemType=5 and ItemCode='上长' and Position='长' THEN GaugeValue3 END) AS 'LongUpDeformationValue3',
max(CASE when ItemType=5 and ItemCode='上长' and Position='长' THEN GaugeValue4 END) AS 'LongUpDeformationValue4',
max(CASE when ItemType=5 and ItemCode='上长' and Position='长' THEN GaugeValue5 END) AS 'LongUpDeformationValue5',
max(CASE when ItemType=5 and ItemCode='中长' and Position='长' THEN GaugeValue1 END) AS 'LongMiddleDeformationValue1',
max(CASE when ItemType=5 and ItemCode='中长' and Position='长' THEN GaugeValue2 END) AS 'LongMiddleDeformationValue2',
max(CASE when ItemType=5 and ItemCode='中长' and Position='长' THEN GaugeValue3 END) AS 'LongMiddleDeformationValue3',
max(CASE when ItemType=5 and ItemCode='中长' and Position='长' THEN GaugeValue4 END) AS 'LongMiddleDeformationValue4',
max(CASE when ItemType=5 and ItemCode='中长' and Position='长' THEN GaugeValue5 END) AS 'LongMiddleDeformationValue5',
max(CASE when ItemType=5 and ItemCode='下长' and Position='长' THEN GaugeValue1 END) AS 'LongDownDeformationValue1',
max(CASE when ItemType=5 and ItemCode='下长' and Position='长' THEN GaugeValue2 END) AS 'LongDownDeformationValue2',
max(CASE when ItemType=5 and ItemCode='下长' and Position='长' THEN GaugeValue3 END) AS 'LongDownDeformationValue3',
max(CASE when ItemType=5 and ItemCode='下长' and Position='长' THEN GaugeValue4 END) AS 'LongDownDeformationValue4',
max(CASE when ItemType=5 and ItemCode='下长' and Position='长' THEN GaugeValue5 END) AS 'LongDownDeformationValue5',
max(CASE when ItemType=5 and ItemCode='左宽' and Position='宽' THEN GaugeValue1 END) AS 'WidthUpDeformationValue1',
max(CASE when ItemType=5 and ItemCode='左宽' and Position='宽' THEN GaugeValue2 END) AS 'WidthUpDeformationValue2',
max(CASE when ItemType=5 and ItemCode='左宽' and Position='宽' THEN GaugeValue3 END) AS 'WidthUpDeformationValue3',
max(CASE when ItemType=5 and ItemCode='左宽' and Position='宽' THEN GaugeValue4 END) AS 'WidthUpDeformationValue4',
max(CASE when ItemType=5 and ItemCode='左宽' and Position='宽' THEN GaugeValue5 END) AS 'WidthUpDeformationValue5',
max(CASE when ItemType=5 and ItemCode='中宽' and Position='宽' THEN GaugeValue1 END) AS 'WidthMiddleDeformationValue1',
max(CASE when ItemType=5 and ItemCode='中宽' and Position='宽' THEN GaugeValue2 END) AS 'WidthMiddleDeformationValue2',
max(CASE when ItemType=5 and ItemCode='中宽' and Position='宽' THEN GaugeValue3 END) AS 'WidthMiddleDeformationValue3',
max(CASE when ItemType=5 and ItemCode='中宽' and Position='宽' THEN GaugeValue4 END) AS 'WidthMiddleDeformationValue4',
max(CASE when ItemType=5 and ItemCode='中宽' and Position='宽' THEN GaugeValue5 END) AS 'WidthMiddleDeformationValue5',
max(CASE when ItemType=5 and ItemCode='右宽' and Position='宽' THEN GaugeValue1 END) AS 'WidthDownDeformationValue1',
max(CASE when ItemType=5 and ItemCode='右宽' and Position='宽' THEN GaugeValue2 END) AS 'WidthDownDeformationValue2',
max(CASE when ItemType=5 and ItemCode='右宽' and Position='宽' THEN GaugeValue3 END) AS 'WidthDownDeformationValue3',
max(CASE when ItemType=5 and ItemCode='右宽' and Position='宽' THEN GaugeValue4 END) AS 'WidthDownDeformationValue4',
max(CASE when ItemType=5 and ItemCode='右宽' and Position='宽' THEN GaugeValue5 END) AS 'WidthDownDeformationValue5',
--max(CASE when ItemType=3 and ItemCode='上长' and Position='长' THEN isnull(CheckResult,'NG') END) AS 'LongUpGaugeResult',
--max(CASE when ItemType=3 and ItemCode='中长' and Position='长' THEN isnull(CheckResult,'NG') END) AS 'LongMiddleGaugeResult',
--max(CASE when ItemType=3 and ItemCode='下长' and Position='长' THEN isnull(CheckResult,'NG') END) AS 'LongDownGaugeResult',
--max(CASE when ItemType=3 and ItemCode='左宽' and Position='宽' THEN isnull(CheckResult,'NG') END) AS 'WidthUpGaugeResult',
--max(CASE when ItemType=3 and ItemCode='中宽' and Position='宽' THEN isnull(CheckResult,'NG') END) AS 'WidthMiddleGaugeResult',
--max(CASE when ItemType=3 and ItemCode='右宽' and Position='宽' THEN isnull(CheckResult,'NG') END) AS 'WidthDownGaugeResult',
--max(CASE when ItemType=5 and ItemCode='上长' and Position='长' THEN isnull(CheckResult,'NG') END) AS 'LongUpDeformationResult',
--max(CASE when ItemType=5 and ItemCode='中长' and Position='长' THEN isnull(CheckResult,'NG') END) AS 'LongMiddleDeformationResult',
--max(CASE when ItemType=5 and ItemCode='下长' and Position='长' THEN isnull(CheckResult,'NG') END) AS 'LongDownDeformationResult',
--max(CASE when ItemType=5 and ItemCode='左宽' and Position='宽' THEN isnull(CheckResult,'NG') END) AS 'WidthUpDeformationResult',
--max(CASE when ItemType=5 and ItemCode='中宽' and Position='宽' THEN isnull(CheckResult,'NG') END) AS 'WidthMiddleDeformationResult',
--max(CASE when ItemType=5 and ItemCode='右宽' and Position='宽' THEN isnull(CheckResult,'NG') END) AS 'WidthDownDeformationResult'
/*Update by zhuss 2014-09-25*/
max(CASE when ItemType=3 and ItemCode='上长' and Position='长' THEN CheckResult END) AS 'LongUpGaugeResult',
max(CASE when ItemType=3 and ItemCode='中长' and Position='长' THEN CheckResult END) AS 'LongMiddleGaugeResult',
max(CASE when ItemType=3 and ItemCode='下长' and Position='长' THEN CheckResult END) AS 'LongDownGaugeResult',
max(CASE when ItemType=3 and ItemCode='左宽' and Position='宽' THEN CheckResult END) AS 'WidthUpGaugeResult',
max(CASE when ItemType=3 and ItemCode='中宽' and Position='宽' THEN CheckResult END) AS 'WidthMiddleGaugeResult',
max(CASE when ItemType=3 and ItemCode='右宽' and Position='宽' THEN CheckResult END) AS 'WidthDownGaugeResult',
max(CASE when ItemType=5 and ItemCode='上长' and Position='长' THEN CheckResult END) AS 'LongUpDeformationResult',
max(CASE when ItemType=5 and ItemCode='中长' and Position='长' THEN CheckResult END) AS 'LongMiddleDeformationResult',
max(CASE when ItemType=5 and ItemCode='下长' and Position='长' THEN CheckResult END) AS 'LongDownDeformationResult',
max(CASE when ItemType=5 and ItemCode='左宽' and Position='宽' THEN CheckResult END) AS 'WidthUpDeformationResult',
max(CASE when ItemType=5 and ItemCode='中宽' and Position='宽' THEN CheckResult END) AS 'WidthMiddleDeformationResult',
max(CASE when ItemType=5 and ItemCode='右宽' and Position='宽' THEN CheckResult END) AS 'WidthDownDeformationResult'
from MES_InspectGauge group by billno) g on g.BillNO=s.BillNO
--left join
--(
-- select distinct a.DispatchNO,a.MachineNO,a.MaterialNO,MAX(a.ID) as ID
-- from MES_Material a
-- join #InspectFirst n on a.DispatchNO=n.DispatchNo and n.MachineNo=a.MachineNO
-- where a.FeedingTime>DATEADD(HH,-2,GETDATE())
-- group by a.DispatchNO,a.MachineNO,a.MaterialNO
-- ) m on m.DispatchNO=c.DispatchNo and m.MachineNO=c.MachineNo
left join MES_InspectWeightRec w on c.BillNO=w.BillNO
left join MES_Item i on c.ItemNO=i.itemno
left join MES_Employee e on e.EmpID=c.CreateMan
left join Sys_User u on u.usercode=c.CheckMan) a order by createtime desc
drop table #InspectFirst
END
---------------------------------------
USE [ChiefmesNEW]
GO
/****** Object: StoredProcedure [dbo].[st_MES_FinalInspection] Script Date: 10/12/2015 10:35:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: hz
-- Create date: 2014.6.25
-- Description: 查询品质检验数据
-- st_MES_FinalInspection '','','','2015-10-10 08:00','2015-10-12 08:00',200,1,'',''
-- =============================================
ALTER PROCEDURE [dbo].[st_MES_FinalInspection]
@BatchNo varchar(20),
@ItemNo varchar(50),
@CheckResult varchar(30),
@BeginDate varchar(20),
@EndDate varchar(20),
@Pagesize int,
@Pageindex int,
@InspectMan varchar(50)='',
--add by zhuss 2015-04-02
@CheckType varchar(50)='',
@BillNO nvarchar(50)=''
AS
BEGIN
declare @strSQL nvarchar(4000)
declare @strWhere nvarchar(4000)
--建临时表保存品质检验记录
IF object_id('tempdb..#FinalInspection') is not NULL drop table #FinalInspection
CREATE TABLE #FinalInspection
(
--ID int identity(1,1),
BillNO nvarchar(50),
ItemNO nvarchar(50),
ItemName nvarchar(500),
BatchNo nvarchar(50),
CreateMan varchar(200),
CreateTime datetime ,
CheckType varchar(50) ,
ConfirmMan nvarchar(50) ,
ConfirmTime datetime,
CheckMan nvarchar(50),
CheckTime datetime,
ProductionTime nvarchar(50),
CheckResult nvarchar(100),
AbnormalNo nvarchar(100),
NoRemark nvarchar(600),
ProdBCCode nvarchar(50),
SpecificGroups nvarchar(50),
ProdNum int
)
set @strWhere=''
set @strSQL='insert into #FinalInspection select * from(
select a.BillNO ,
a.ItemNO,
b.ItemName,
a.BatchNo,
a.CreateMan,
a.CreateTime ,
a.CheckType,
a.ConfirmMan ,
a.ConfirmTime,
a.CheckMan,
a.CheckTime,
ProductionTime,a.CheckResult,AbnormalNo,a.NoRemark,
case when a.ProdBCCode=''AC'' then ''白班'' else ''晚班'' end ProdBCCode,
SpecificGroups,a.ProdNum from MES_Inspect a left join MES_Item b on a.ItemNO=b.ItemNO '
--set @strWhere=@strWhere+' ) a where 1=1 and CheckType in (5,6)'
--update by zhuss 2015-04-02
declare @strCheckType varchar(100)
select @strCheckType=case when @CheckType='' then ' and CheckType in(5,6)' else ' and CheckType='+@CheckType end
set @strWhere=@strWhere+' ) a where 1=1 '+@strCheckType
--if(@InspectMan<>'')
--begin
-- set @strWhere=@strWhere+' and CreateMan='''+@InspectMan+''''
--end
if @BatchNo<>''
begin
set @strWhere=@strWhere+' and BatchNo like ''%'+@BatchNo+'%'''
end
if @ItemNo<>''
begin
set @strWhere=@strWhere+' and ItemNo like ''%'+@ItemNo+'%'''
end
if @CheckResult<>''
begin
set @strWhere=@strWhere+' and CheckResult like ''%'+@CheckResult+'%'''
end
--20150925ST
if @BillNO<>''
begin
set @strWhere=@strWhere+' and BillNO like ''%'+@BillNO+'%'''
end
--20150925End
if @BeginDate<>''
begin
set @strWhere=@strWhere+' and convert(varchar(19),CreateTime,121) >='''+convert(varchar(10),@BeginDate,121)+''''
end
if @EndDate<>''
begin
set @strWhere=@strWhere+' and convert(varchar(19),CreateTime,121) <='''+convert(varchar(10),@EndDate,121)+''''
end
set @strWhere=@strWhere+' order by Createtime desc'
print @strSQL+@strWhere
execute(@strSQL+@strWhere)
update f set CreateMan=isnull(u.Name,e.EmpNameCN) from #FinalInspection f
left join MES_Employee e on e.EmpID=f.CreateMan
left join Sys_User u on u.UserCode=f.CreateMan
update n set CheckMan=isnull(u.Name,e.EmpNameCN) from #FinalInspection n
left join Sys_User u on n.CheckMan=u.UserCode
left join MES_Employee e on n.CheckMan=e.EmpID
declare @CreateManCn varchar(50)
if(@InspectMan<>'')
begin
select @CreateManCn=Name from Sys_User where UserCode like '%'+@InspectMan+'%' or Name like '%'+@InspectMan+'%'
if(@CreateManCn='' or @CreateManCn is null)
begin
select @CreateManCn=EmpNameCN from MES_Employee where EmpID like '%'+@InspectMan+'%' or EmpNameCN like '%'+@InspectMan+'%'
end
delete a from #FinalInspection a
LEFT join (select * from #FinalInspection where CreateMan=@CreateManCn) b on a.BillNO=b.BillNO
where b.BillNO is null
end
alter table #FinalInspection
add ID int not null identity(1,1)
declare @row_from int, @row_to int,@out_total_rows int
select @out_total_rows = count(*) from #FinalInspection
print @out_total_rows
execute st_MES_RS_Pages @out_total_rows, @Pagesize, @Pageindex, @row_from output, @row_to output
select * from #FinalInspection
where ID between @row_from and @row_to
order by ID
select @out_total_rows
END
MES系统的有用存储过程的更多相关文章
- ERP系统和MES系统的区别
公司说最近要上一套erp系统,说让我比较一下,erp系统哪个好,还有mes系统,我们适合上哪个系统,其实我还真的不太懂,刚接触erp跟mes的时候,对于两者的概念总是傻傻分不清楚,总是觉得既然都是为企 ...
- 【详解】ERP、APS与MES系统是什么?
ERP是什么?MES是什么?APS又是什么?无论他们有什么功能,对企业有什么意义,不过都是计算机在读写一些数据而已.实际上这一切的本质不过是数据在硬盘和内存中快速的读和写. ERP是--,APS是-- ...
- MES系统学习
MES系统是当今制造型企业信息化的热点,而统一建模语言UML是面向对象建模的标准语言,在软件工程发挥着重要作用.MES系统如何进行UML建模呢,今天和大家重点讨论一下MES系统的UML建模方法,请看本 ...
- 第三章——使用系统函数、存储过程和DBCC SQLPERF命令来监控SQLServer(3)
原文:第三章--使用系统函数.存储过程和DBCC SQLPERF命令来监控SQLServer(3) 本文为这个系列最后一篇.将是如何使用DBCC命令来监控SQLServer日志空间的使用情况. 前言: ...
- 浅谈MES系统SMT的JIT功能(一):JIT原理
前段时间帮忙客户实现了MES系统的SMT线上的JIT功能(JIT功能只适合电子行业的生产线),今天就来谈谈JIT功能是什么,为什么工厂车间需要用到JIT等等一些经验 首先说说JIT: 准时制生产方式( ...
- 听说你的MES系统又失败了?
前些日子,一位前同事跟我抱怨,他们做的MES系统,凉凉了.这样的话,我从不同人口中听到过不止一次. 我们做的系统,做到一半做不下去了...... 我们的系统,工人都不爱用...... 不只是MES,所 ...
- C#C/S框架演示 (MES系统)
之前做过一个MES系统,发一些里面的截图.如果有朋友也用这个框架.或者有兴趣可以一起学习学习.使用开发工具VS2013,数据库SqlServer2008和Oracle11C.插件dev15.2,开发模 ...
- MES系统在小批量电子行业生产管理中的应用
小批量电子产品生产管理的主要问题 电子电器制造类企业,既有单件小批量生产,也有批量生产:有按库存生产,也有按订单生产,属于典型的离散制造行业.因产品的不同其生产工艺流程也不尽相同,生产设备的布置不是按 ...
- 不了解MES系统中的看板管理?看完本文就懂了
如果想要在生产车间中,让生产过程管理都处在“看得见”的状态,那么看板可视化管理的导入是你的不二选择. MES看板包括四个部分:生产任务看板.各生产单位生产情况看板.质量看板和物料看板,其中生产任务看板 ...
随机推荐
- datatables 服务器返回数据后的处理-表格数据属性的操作方法(ajax.dataSrc)
http://dt.thxopen.com/reference/option/ajax.dataSrc.html http://datatables.net/reference/option/ajax ...
- <三>面向对象分析之UML核心元素之参与者
一:版型 --->在UML里有一个概念叫版型.有些书里也称类型,构造型. --->这个概念是对一个UML元素基础定义的扩展.在同一个元素基础定义的基础上赋予特别 ...
- 【JSP】弹出带输入框可 确认密码 对话框
<body> <input type="submit" value="删除历史全部订单" onclick="deleteall()& ...
- tcprstat的使用方式
两种使用方式:1)本机直接在线采集:2)分析tcpdump采集到的离线pcap文件 1. 本机直接在线采集 参数: -p :指定只采集此TCP port的请求 -t : 采集输出的时间间 ...
- Delphi中编辑word
其他(28) //启动Word try wordapplication1.connect; except messagedlg('word may not be ins ...
- codeforces 696A Lorenzo Von Matterhorn 水题
这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...
- HDU-4861 Couple doubi
http://acm.hdu.edu.cn/showproblem.php?pid=4861 Couple doubi Time Limit: 2000/1000 MS (Java/Others) ...
- Myeclipse8.5 svn插件安装两种方式
第一种方式:(亲测成功)第一步:准备插件包:site-1.6.18.zip解压该包里面有features和plugins文件夹,删除该包里面的xml结尾的文件. 第二:我的Myeclipse8.5安装 ...
- Hadoop 学习之 FAQ
在Hadoop的学习与使用过程中同样如此.这里为大家分享Hadoop集群设置中经常出现的一些问题,以下为译文: 1.Hadoop集群可以运行的3个模式? 单机(本地)模式 伪分布式模式 全分布式模式 ...
- IOS-day01_OC中类的创建以及使用
OC中定义类 // 设计一个车类 @implementation Car : NSObject // 这个大括号里面写所有的属性 { @public int wheels ;//轮子个数 double ...