USE [ChangHong_612]
GO
/****** Object: StoredProcedure [dbo].[st_MES_RptInspectWeight] Script Date: 09/10/2015 18:02:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER proc [dbo].[st_MES_RptInspectWeight]
(
@ItemNo varchar(50) ='860027141' --产品编号
,@ItemName varchar(50) ='' --产品描述
,@BeginTime VARCHAR(19)='2014-11-07 08:30' --计划开始时间
,@EndTime varchar(19)='2014-11-12 20:30' --计划结束时间
,@MachineNo varchar(20)=''
)
/*************
creator: zhuss
create date: 2014.09.25
update by fsq 2014.09.29 修改偏差、标准周期、只显示首检记录
Remark: 查询品质检测重量记录
exec st_MES_RptInspectWeight '850130560','','2013-06-28 15:00:00','2015-08-28 22:50:12',''
**************/
as
begin

--查询重量记录
select i.ItemName,r.BillNO,r.InspectDate,r.ItemNo,r.ThisSign,r.MothSign,r.FixWeight,
case when (r.PartWeight=0 or r.PartWeight is null) then '-' --else
--CONVERT(varchar(10),(isnull(r.Weight,0)+ isnull(r.Weight2,0)+isnull(r.Weight3,0)+isnull(r.Weight4,0)+isnull(r.Weight5,0))/
--case when r.Weight is null and r.Weight2 is null and r.Weight3 is null and r.Weight4 is null and r.Weight5 is null then r.PartWeight
--else
-- (case when r.Weight IS not null then 1 else 0 end+case when r.Weight2 IS not null then 1 else 0 end+case when r.Weight3 IS not null then 1 else 0 end
--+case when r.Weight4 IS not null then 1 else 0 end+case when r.Weight5 IS not null then 1 else 0 end) end) end PartWeight
when r.Weight is null and r.Weight2 is null and r.Weight3 is null and r.Weight4 is null and r.Weight5 is null then r.PartWeight
else CONVERT(varchar(10),(isnull(r.Weight,0)+ isnull(r.Weight2,0)+isnull(r.Weight3,0)+isnull(r.Weight4,0)+isnull(r.Weight5,0))/
case
(
case when r.Weight IS not null and r.Weight<>0 then 1 else 0 end+
case when r.Weight2 IS not null and r.Weight2<>0 then 1 else 0 end+
case when r.Weight3 IS not null and r.Weight3<>0 then 1 else 0 end+
case when r.Weight4 IS not null and r.Weight4<>0 then 1 else 0 end+
case when r.Weight5 IS not null and r.Weight5<>0 then 1 else 0 end
)
when 0 then 1 else
(
case when r.Weight IS not null and r.Weight<>0 then 1 else 0 end+
case when r.Weight2 IS not null and r.Weight2<>0 then 1 else 0 end+
case when r.Weight3 IS not null and r.Weight3<>0 then 1 else 0 end+
case when r.Weight4 IS not null and r.Weight4<>0 then 1 else 0 end+
case when r.Weight5 IS not null and r.Weight5<>0 then 1 else 0 end
)
end

) end PartWeight

,case when (r.GateWeight=0 or r.GateWeight is null) then '-' else CONVERT(varchar(10),r.GateWeight) end GateWeight
,r.ShapeCycle,dbo.FN_GetEmpNameByID(r.InspectMan) InspectMan,
MachineNo,InspectDate2=CONVERT(varchar(19),r.InspectDate,120),
--InjectionCycle=i.ItemCycle,
i.MouldNO
,InjectionCycle=(select max(InjectionCycle) from MES_MouldDetail m join FN_SplitSTR(i.MouldNO,',') b on b.Col=m.MouldNO),
MaterialInfo=[dbo].[FN_GetMaterialInfo](s.MachineNo,s.DispatchNo,s.DispatchPrior,r.InspectDate,1),
ItemNetWeight=CONVERT(varchar(10),isnull(i.NetWeight,0)-abs(isnull(i.NetWeightDown,0)))+'~'+CONVERT(varchar(10),isnull(i.NetWeight,0)+abs(isnull(i.NetWeightUp,0))),
ErrWeight=case when isnull(r.PartWeight,0)<isnull(i.NetWeight,0)-abs(isnull(i.NetWeightDown,0))
then CONVERT(varchar(20),isnull(r.PartWeight,0)-(isnull(i.NetWeight,0)-abs(isnull(i.NetWeightDown,0))))
when isnull(i.NetWeight,0)-abs(ISNULL(i.NetWeightDown,0))<=isnull(r.PartWeight,0)
and isnull(r.PartWeight,0)<=isnull(i.NetWeight,0)+abs(ISNULL(i.NetWeightUp,0))
then '/'
else '+'+convert(varchar(20),isnull(r.PartWeight,0)-(isnull(i.NetWeight,0)+abs(isnull(i.NetWeightUp,0)))) end
from MES_InspectWeightRec r
join MES_Item i on i.ItemNO=r.ItemNo
left join MES_Inspect s on r.BillNO=s.BillNO
where not ((partweight=0 and gateweight=0) or (partweight is null and gateweight is null))
--and s.CheckType=2
--update by zhuss 2014-10-21
and s.CheckType in(1,2,3,4)
and (@ItemNO='' or r.ItemNO like '%'+@ItemNO+'%')
and (@ItemName='' or i.ItemName like '%'+@ItemName+'%')
and (@BeginTime='' or CONVERT(varchar(19),r.InspectDate,120)>=@BeginTime)
and (@EndTime='' or CONVERT(varchar(19),r.InspectDate,120)<=@EndTime)
and (@MachineNo='' or s.MachineNo like '%'+@MachineNo+'%')
order by r.InspectDate desc
end

-----------------------------------------------------------------------------------------------

USE [ChangHong_612]
GO
/****** Object: UserDefinedFunction [dbo].[FN_GetMaterialInfo] Script Date: 09/10/2015 18:06:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*************
creator: zhuss
create date: 2014.09.25
Module: Public
Remark: 返回3小时内原料信息
**************/
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

sql 调用函数的方法的更多相关文章

  1. FastReport里面正确调用函数的方法

    FastReport里面正确调用函数的方法   错误:  [FormatDateTime('yyyy-mm-dd',[frxDBDataset1."日期"])] --------- ...

  2. JavaScript调用函数的方法

    摘要:这篇文章详细的介绍了Javascript中各种函数调用的方法及其原理,对于理解JavaScript的函数有很大的帮助! 一次又一次的,我发现,那些有bug的Javascript代码是由于没有真正 ...

  3. 父窗口和iframe子窗口之间相互传递参数和调用函数或方法

    1.父窗口向子窗口传递参数: 可以在url中添加参数:2.html?a=1&b=2&c=3 然后在子页面上可用js解析,提供一个函数: function getQueryStr(sAr ...

  4. shell 从函数文件中调用函数的方法

    你可以把所有的函数存储在一个函数文件中 你可以把所有的文件函数加载到当前脚本或命令行 加载函数文件中所有函数的方法: source xxx.sh

  5. 5种 JavaScript 调用函数的方法

    一次又一次的,我发现,那些有bug的Javascript代码是由于没有真正理解Javascript函数是如何工作而导致的(顺便说一下,许多那样的代码是我写的).JavaScript拥有函数式编程的特性 ...

  6. PHPCMS联动菜单的调用函数get_linkage方法详解

    v9联动菜单调用方法[注意此为内容页调用方法 {get_linkage($areaid,1,' >> ',1)} 显示效果: 湖北省 >> 武汉市 >> 汉阳区 [ ...

  7. Unity3D NGUI 二 NGUI Button怎样接受用户点击并调用函数,具体方法名称是什么

    a.直接监听事件 把下面脚本直接绑定在按钮上,当按钮点击时就可以监听到,这种方法不太好很不灵活. void OnClick(){ Debug.Log("Button is Click!!!& ...

  8. js页面加载时候的调用函数的方法

    方法一:jquery 中:$(function(){}) 括号内写你的内容 方法二:html <body onload=''> <script type="text/jav ...

  9. php中调用用户自定义函数的方法:call_user_func,call_user_func_array

    看UCenter的时候有一个函数call_user_func,百思不得其解,因为我以为是自己定义的函数,结果到处都找不到,后来百度了一下才知道call_user_func是内置函数,该函数允许用户调用 ...

随机推荐

  1. UVa 1347 (双线程DP) Tour

    题意: 平面上有n个坐标均为正数的点,按照x坐标从小到大一次给出.求一条最短路线,从最左边的点出发到最右边的点,再回到最左边的点.除了第一个和最右一个点其他点恰好只经过一次. 分析: 可以等效为两个人 ...

  2. TYVJ 1066 合并果子【优先队列】

    题意:给出n堆果子,需要将n堆果子合并成一堆,问将所有堆的果子合成一堆所需要花费的最少的力气 因为要使耗费力气最小,即需要每次搬动的那堆重量小,所以可以选取两堆最轻的合并,合并之后再插入还没有合并的堆 ...

  3. PHP单元测试工具PHPUnit初体验

    今天接到了个任务,需要对数字进行计算,因为涉及到整数,小数,和科学计数法等很多条件,所以人工测试非常麻烦,于是想到了PHP的单元测试工具PHPUnit,所以写个文档备查. 看了PHPUnit的文档之后 ...

  4. Darwin Streaming Server 简介

    Darwin Streaming Server     概要 Darwin Streaming Server简称DSS.DSS是Apple公司提供的开源实时流媒体播放服务器程序.整个程序使用C++编写 ...

  5. 一天一个Java基础——序列化

    1.概念 Java的“对象序列化”能将一个实现了Serializable接口的对象转换成一组byte,这样日后要用这个对象的时候,能把这些byte数据恢复出来,并据此重新构建那个对象. 对象序列化能实 ...

  6. Java中实现复制文件或文件夹

     拷贝一个文件的算法比较简单,当然,可以对它进行优化,比如使用缓冲流,提高读写数据的效率等.但是在复制文件夹时,则需要利用Flie类在目标文件夹中创建相应的目录,并且使用递归方法. [java] vi ...

  7. 【转】C++ 内存分配(new,operator new)详解

    本文主要讲述C++ new运算符和operator new, placement new之间的种种关联,new的底层实现,以及operator new的重载和一些在内存池,STL中的应用. 一 new ...

  8. PLSQL Developer报“动态执行表不可访问,本会话的自动统计被禁止”的解决方案

    现象与提示: 第一次用PLSQL Developer连接数据库,若用sys用户登录并操作则正常,若用普通用户比如haishu登录并创建一个表则报错"动态执行表不可访问,本会话的自动统计被禁止 ...

  9. Flash Player”又来了“!

    2012年,Adobe宣布缩小对Linux平台的支持,自Flash Player 11.2版本之后,只为Linux平台上的Flash Player提供安全更新和bug修复,而不再提供版本更新. 四年之 ...

  10. python 资料

    主站: 主页:http://python.org/下载:http://python.org/download/文档:http://python.org/doc/ books: ActivePython ...