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是内置函数,该函数允许用户调用 ...
随机推荐
- I.MX6 lcd lvds hdmi bootargs
/********************************************************************* * I.MX6 lcd lvds hdmi bootarg ...
- zend studio安装xdebug调试工具
1. 软件准备 登录xdebug 版本检测地址 http://xdebug.org/wizard.php :将phpinfo产生的数据页面复制到其文本框内,显示类似如下内容: 二.将下载的xdebu ...
- tomcat 调优
1 总是遇到read time out ,socket什么的 <Executor name="tomcatThreadPool" namePrefix=& ...
- Ruby基础数据类型
#数字分为证书Integer,浮点数Float(对应与其他语言中的double),和复数Complex #整数又分为Fixnum和Bignum,Fixnum和Bignum会互相转换,这些都是ruby自 ...
- xcode升级,报错 libxml/tree.h not found (Xcode4.6解决方案)
转:http://blog.csdn.net/yangxuanlun/article/details/8639075 Xcode升级到4.6以后,他妈的,libxml/tree.h找不到了,搞了大半天 ...
- [Irving] SQL 2005/SQL 2008 备份数据库并自动删除N天前备份的脚本
以下为SQL脚本,本人以执行计划来调用,所以改成了执行命令,大家可根据自己需要改为存储过程使用 )='E:\MsBackUp\SqlAutoBackup\' --备份路径; --备份类型为全备,1为差 ...
- Asp.Net中的获取Web.config中设置的参数!(前后台的代码示例)
一.Web.config中设置代码 <appSettings> <add key="deleted" value="1" ...
- MorningSale 介绍
MorningSale是一个WEB端的收集门店销售数据,显示销售数据的简单系统,我相信该系统能够有效的提高销售公司在门店销售数据收集 汇总 分析方面的工作效率. 主要功能介绍如下: 1.查看某个店面 ...
- 求职基础复习之快速排序c++版
#include<iostream> using namespace std; int partition(int a[],int p,int q){ int x = a[q]; ; fo ...
- [HIve - LanguageManual] Union
Union Syntax select_statement UNION ALL select_statement UNION ALL select_statement ... UNION is use ...