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 ‘%‘[email protected]+‘%‘)
and (@ItemName=‘‘ or i.ItemName like ‘%‘[email protected]+‘%‘)
and (@BeginTime=‘‘ or CONVERT(varchar(19),r.InspectDate,120)>[email protected])
and (@EndTime=‘‘ or CONVERT(varchar(19),r.InspectDate,120)<[email protected])
and (@MachineNo=‘‘ or s.MachineNo like ‘%‘[email protected]+‘%‘)
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 @[email protected]*3600

--循环查找一天内的加料信息
while (not exists(select * from MES_Material m
where DATEDIFF(ss,m.FeedingTime,@InspectDate)>0
and DATEDIFF(ss,m.FeedingTime,@InspectDate)<@TotalTimes
and [email protected] and [email protected]
and [email protected]
) and @m<=24
)
begin
set @[email protected]+3
select @[email protected]*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 [email protected] and [email protected] and [email protected]
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 [email protected] and [email protected] and [email protected]
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 [email protected] and [email protected] and [email protected]
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 [email protected] and [email protected] and [email protected]
end
end
select @count=Count(*),@i=1 from @tbMaterialInfo
while(@i<[email protected])
begin
if(@ReturnMaterialInfo=‘‘)
select @ReturnMaterialInfo=MaterialInfo from @tbMaterialInfo where [email protected]
else
set @[email protected]+‘,‘+(select MaterialInfo from @tbMaterialInfo where [email protected])
set @[email protected]+1
end
return @ReturnMaterialInfo
end

时间: 2024-08-29 06:16:34

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

JavaScript调用函数的方法

摘要:这篇文章详细的介绍了Javascript中各种函数调用的方法及其原理,对于理解JavaScript的函数有很大的帮助! 一次又一次的,我发现,那些有bug的Javascript代码是由于没有真正理解Javascript函数是如何工作而导致的(顺便说一下,许多那样的代码是我写的).JavaScript拥有函数式编程的特性,当我们选择面对它的时候,这将成为我们前进的阻碍.  作为初学者,我们来测试五种函数调用的方法,从表面来看我们会认为那些函数与C#中函数的作用非常相似,但是我们一会儿可以看到

5种 JavaScript 调用函数的方法

一次又一次的,我发现,那些有bug的Javascript代码是由于没有真正理解Javascript函数是如何工作而导致的(顺便说一下,许多那样的代码是我写的).JavaScript拥有函数式编程的特性, 当我们选择面对它的时候,这将成为我们前进的阻碍. 作为初学者,我们来测试五种函数调用的方法,从表面来看我们会认为那些函数与C#中函数的作用非常相似,但是我们一会儿可以看到还是有非常重要的不同的地方的,忽视这些差异无疑会导致难于跟踪的bug.首先让我们创建一个简单的函数,这个函数将在将在下文中使用

unity gameObject之间的调用函数的方法

例如:你想调用已经实例了的Player对象里的PlayJumpTo 代码里的Jump()函数 private PlayJumpTo playJumpto; private GameObject playerObj; void Start() { playerObj = GameObject.FindWithTag ("Player"); playJumpto = playerObj.GetComponent<PlayJumpTo>(); } void Fun() { pla

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

方法一:jquery 中:$(function(){}) 括号内写你的内容 方法二:html <body onload=''> <script type="text/javascript"> window.onload=function()//用window的onload事件,窗体加载完毕的时候 { //do something } </script> 方法3  $().ready(function(){ alert("aaa")

delphi通过函数名动态调用函数的方法

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TMyCacl = class(TObject) public { Public declarations } function DynamicFun(funName: string; const a, b: integer): integer;

Go - 反射中 函数 和 方法 的调用

上一篇文章 说到了 Golang 中的反射的一些基本规则,重点就是文章中最后的三点,但是这篇文章并没有说如何在反射中调用函数和方法,这就是接下来要说的. 反射中调用 函数 众所周知,Golang 中的函数是可以像普通的 int.float 等类型变量那样作为值的,例如: package main import "fmt" func hello() { fmt.Println("Hello world!") } func main() { hl := hello hl

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

看UCenter的时候有一个函数call_user_func,百思不得其解,因为我以为是自己定义的函数,结果到处都找不到,后来百度了一下才知道call_user_func是内置函数,该函数允许用户调用直接写的函数并传入一定的参数,不可谓不强大,总结一下,写到这篇日志里面吧. 先放上来别人的例子吧: call_user_func函数类似于一种特别的调用函数的方法,使用方法如下: function a($b,$c) { echo $b; echo $c; } call_user_func('a',

李洪强iOS开发之OC[017]函数和方法的区别

// //  main.m //  15 - 函数和对象的方法的区别 // //  Created by vic fan on 16/7/12. //  Copyright © 2016年 李洪强. All rights reserved. // 函数和对象方法的区别 对象方法: - (void)run; #import <Foundation/Foundation.h> @interface Person : NSObject{ @public //定义实例变量 NSString *_nam

用函数的地址调用函数 C++ MFC

先说一段废话,幸亏我汇编基础(基础 基础 基础)扎实,否则这个问题真的恶心到我了正题  因为有特殊需求, 需要写一个类似于接口的功能,但是因为用到的次数不多再加上C++写接口各种麻烦所以想通过函数的地址调用该函数,并且能正常的传递参数.但调用过程和被调函数是不在一个类的,调用起来又是各种麻烦这几天我翻烂了百度, 都没找到方法,什么函数回调啊,通过函数地址调用函数啊,还有什么接口之类的天......最后想起来我之前用过的易语言里有人写过这个功能,打算拷贝过来,但是也有不足(稍后会说),先上翻译成C