sql 调用函数的方法
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 调用函数的方法的更多相关文章
- FastReport里面正确调用函数的方法
FastReport里面正确调用函数的方法 错误: [FormatDateTime('yyyy-mm-dd',[frxDBDataset1."日期"])] --------- ...
- JavaScript调用函数的方法
摘要:这篇文章详细的介绍了Javascript中各种函数调用的方法及其原理,对于理解JavaScript的函数有很大的帮助! 一次又一次的,我发现,那些有bug的Javascript代码是由于没有真正 ...
- 父窗口和iframe子窗口之间相互传递参数和调用函数或方法
1.父窗口向子窗口传递参数: 可以在url中添加参数:2.html?a=1&b=2&c=3 然后在子页面上可用js解析,提供一个函数: function getQueryStr(sAr ...
- shell 从函数文件中调用函数的方法
你可以把所有的函数存储在一个函数文件中 你可以把所有的文件函数加载到当前脚本或命令行 加载函数文件中所有函数的方法: source xxx.sh
- 5种 JavaScript 调用函数的方法
一次又一次的,我发现,那些有bug的Javascript代码是由于没有真正理解Javascript函数是如何工作而导致的(顺便说一下,许多那样的代码是我写的).JavaScript拥有函数式编程的特性 ...
- PHPCMS联动菜单的调用函数get_linkage方法详解
v9联动菜单调用方法[注意此为内容页调用方法 {get_linkage($areaid,1,' >> ',1)} 显示效果: 湖北省 >> 武汉市 >> 汉阳区 [ ...
- Unity3D NGUI 二 NGUI Button怎样接受用户点击并调用函数,具体方法名称是什么
a.直接监听事件 把下面脚本直接绑定在按钮上,当按钮点击时就可以监听到,这种方法不太好很不灵活. void OnClick(){ Debug.Log("Button is Click!!!& ...
- js页面加载时候的调用函数的方法
方法一:jquery 中:$(function(){}) 括号内写你的内容 方法二:html <body onload=''> <script type="text/jav ...
- php中调用用户自定义函数的方法:call_user_func,call_user_func_array
看UCenter的时候有一个函数call_user_func,百思不得其解,因为我以为是自己定义的函数,结果到处都找不到,后来百度了一下才知道call_user_func是内置函数,该函数允许用户调用 ...
随机推荐
- css3的背景多重运用
效果图: 简单代码: http://www.developerdrive.com/2013/08/introducing-css3-multiple-backgrounds/ 演示地址: http:/ ...
- 根据dwarfdump、Symbolicatecrash查找错误代码
dSYM文件获取:1.build2.Archive 获取app UUID 命令:dwarfdump --uuid YourApp.app.dSYM 1.YourApp.app/YourApp2.You ...
- I.MX6 Linux udev porting
/*********************************************************************** * I.MX6 Linux udev porting ...
- ms_sql:drop and create a job
/****** Object: Job [syncData_23_00] Script Date: 09/30/2013 16:48:32 ******/ ) IF EXISTS (SELECT jo ...
- POJ 2549 Sumsets
Sumsets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10593 Accepted: 2890 Descript ...
- [Everyday Mathematics]20150211 Carlson inequality
$$\bex a_n\geq 0\ra \vsm{n}a_n\leq \sqrt{\pi}\sex{\vsm{n}a_n^2}^{1/4} \sex{\vsm{n}n^2a_n^2}^{1/4}, \ ...
- redis发布/订阅模式
其实在很多的MQ产品中都存在这样的一个模式,我们常听到的一个例子 就是邮件订阅的场景,什么意思呢,也就是说100个人订阅了你的博客,如果博主发表了文章,那么100个人就会同时收到通知邮件,除了这个 场 ...
- 网站sqlserver提权操作
在入侵过程中,得到SQLserver的权限,想进一步得到system权限的方法总结 *************************** 利用xp_cmdshell **************** ...
- [BILL WEI] stimulsoft 分组页眉页脚的使用
我们在通过stimulsoft设计报表的时候,有的时候,需要做出如下图报表样式 这个时候,因为箱号是分开扩展的,我们就需要用到分组页眉了,如下图demo跟实例所示:
- 《零成本实现Web自动化测试--基于Selenium》第三章 Selenium-IDE
1.简介 Selenium-IDE(集成开发环境)是一种开发selenium测试案例的工具.是一种易用的Firefox插件.你可以通过文字菜单,在当前页面上选择一个UI元素,接着挑选与UI元素相关的s ...