`
jessen163
  • 浏览: 462967 次
  • 性别: Icon_minigender_1
  • 来自: 潘多拉
社区版块
存档分类
最新评论

写的几个存储过程,复习下了

阅读更多
ALTER proc [dbo].[proc_jiancebiao]

@zhiling varchar(1000)

AS

/***************************

名稱: [proc_jiancebiao]

作用: 製令多階物料用量表(檢測表)

參數:@zhiling,制令號,用","分隔開如:611603084,611000922

作者:kk

時間:-6-1

測試: exec proc_jiancebiao '611603084,611000922'

****************************/

SET NOCOUNT ON

declare @t_level table(itemcode varchar(20),child_itemcode varchar(20),level int,qty int)

declare @level int

declare @temp1 table(itemid varchar(20),itemname nvarchar(100),standards nvarchar(100),unit nvarchar(10),qty int)

declare @temp2 table(itemid varchar(20),storeQty int)

declare @temp3 table(itemid varchar(20),notGetQty int)

declare @temp4 table(itemid varchar(20),notReachQty int)

set @level=1

insert @t_level select ib01,ib03,@level,ib04*num from bomib t1

join (select mb04 as itemcode,mb06 as num from mocmb where ','+@zhiling+',' like '%'+mb01+mb02+'%') t2 on t1.ib01=t2.itemcode

while @@rowcount>0

begin

    set @level=@level+1

    insert @t_level select t1.ib01,t1.ib03,@level,t1.ib04*t2.qty from bomib t1

    inner join @t_level t2 on t1.ib01=t2.child_itemcode

    where t2.level=@level-1

end

--基本資料

insert @temp1 select child_itemcode as itemid,t2.ma02 as itemname,t2.ma03 as standards,t2.ma05 as unit,sum(qty) as qty from @t_level t1

join invma t2 on t1.child_itemcode = t2.ma01

group by child_itemcode,t2.ma02,t2.ma03,t2.ma05

--庫存數量

insert @temp2 select * from openrowset('MSDASQL',

'srsdb';'';'',

'select mb01 as itemid,sum(mb04) as store_num from invmb group by mb01')

--下單未領料

insert @temp3 select me04 as itemid,sum(me07) as notGetQty from mocme

where me10='N' and isnull(rtrim(me11),'')<>'' and dbo.changeDXDate(me11)>DATEADD(mm,-4,getdate()) and me01 in ('631','633','651','652')

group by me04

--在途量

insert @temp4 select tb04 as itemid,sum(isnull(tb06,0))-sum(isnull(tb07,0)) as notReachQty from purtb

where tb14='N' and isnull(rtrim(tb13),'')<>'' and dbo.changeDXDate(tb13)>DATEADD(mm,-4,getdate())

group by tb04

--查詢結果

select '制令別' as itemid,'制令號' as itemname,'品號' as standards,'數量' as unit,qty=null,storeqty=null,notgetqty=null,notreachqty=null

union all select mb01,mb02,mb04,cast(mb06 as varchar(15)),null,null,null,null from mocmb where ','+@zhiling+',' like '%'+mb01+mb02+'%'

union all select '------------','------------','-------------','------------',null,null,null,null

union all

select a.*,b.storeQty,isnull(c.notGetQty,0)as notGetQty,isnull(d.notReachQty,0) as notReachQty

from @temp1 a

left join @temp2 b on a.itemid=b.itemid

left join @temp3 c on a.itemid=c.itemid

left join @temp4 d on a.itemid=d.itemid

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

ALTER proc [dbo].[p_useThisItemProduct]

@itemcode varchar(20)

AS

/***************************

名稱:[p_useThisItemProduct]

作用:所有用到此物料的成品及其成本分析

參數:@itemcode ,物料品號

作者:kk

時間:-6-1

測試: exec p_useThisItemProduct 'PBXSEBIR6027AW2'

****************************/

declare @t_level table(itemcode varchar(20),level int)

declare @level int

set @level=1

--查找所有用到此物料的成品及半成品

insert @t_level select ib01,@level from bomib where ib03=@itemcode

while @@rowcount>0

begin

    set @level=@level+1

    insert @t_level select t1.ib01,@level from bomib t1

    inner join @t_level t2 on t1.ib03=t2.itemcode

    where t2.level=@level-1

end

--只保留成品

delete from @t_level where left(ltrim(itemcode),1)<>'F'

--展開物料清單,計算成本,使用自定義函數dbo.fun_costAnalyse()

select t1.itemcode,t2.ma02 as itemname,t2.ma03 as standards,dbo.fun_costAnalyse(t1.itemcode) as cost from @t_level t1

left join invma t2 on t1.itemcode = t2.ma01

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

ALTER proc [dbo].[po_bomZ]

@start_date varchar(6),

@end_date varchar(6)

AS

/***************************

名稱:po_bomz

作用:未出貨訂單多階物料需求用量表

參數:@start_date,開始日期,@end_date,結束日期

作者:kk

時間:-6-1

測試: exec po_bomz '060530','060531'

****************************/

declare @t table(itemcode varchar(20),num int)

declare @t_level table(itemcode varchar(20),child_itemcode varchar(20),level int,qty int)

declare @level int

declare @temp1 table(itemid varchar(20),itemname nvarchar(100),standards nvarchar(100),unit nvarchar(10),qty int)

declare @temp2 table(itemid varchar(20),storeQty int)

declare @temp3 table(itemid varchar(20),notGetQty int)

declare @temp4 table(itemid varchar(20),notReachQty int)

set @level=1

insert @t select tc04 as itemcode,sum(isnull(tc06,0))-sum(isnull(tc07,0)) as num from coptb t1

left join coptc t2 on t1.tb01+t1.tb02=t2.tc01+t2.tc02

where t1.tb03 >= @start_date and t1.tb03<'1000000' and (t1.tb03<= @end_date or @end_date='') and tc11='N'

group by tc04

insert @t_level select ib01,ib03,@level,ib04*num from bomib t1

inner join @t t2 on t1.ib01=t2.itemcode

while @@rowcount>0

begin

    set @level=@level+1

    insert @t_level select t1.ib01,t1.ib03,@level,t1.ib04*t2.qty from bomib t1

    inner join @t_level t2 on t1.ib01=t2.child_itemcode

    where t2.level=@level-1

end

insert @temp1 select child_itemcode as itemid,t2.ma02 as itemname,t2.ma03 as standards,t2.ma05 as unit,sum(qty) as qty from @t_level t1

join invma t2 on t1.child_itemcode = t2.ma01

group by child_itemcode,t2.ma02,t2.ma03,t2.ma05

insert @temp2 select mb01 as itemid,sum(mb04) as store_num from invmb group by mb01

insert @temp3 select me04 as itemid,sum(me07) as notGetQty from mocme

where me10='N' and isnull(rtrim(me11),'')<>'' and dbo.changeDXDate(me11)>DATEADD(mm,-4,getdate()) and me01 in ('631','633','651','652')

group by me04

insert @temp4 select tb04 as itemid,sum(isnull(tb06,0))-sum(isnull(tb07,0)) as notReachQty from purtb

where tb14='N' and isnull(rtrim(tb13),'')<>'' and dbo.changeDXDate(tb13)>DATEADD(mm,-4,getdate())

group by tb04

select a.*,b.storeQty,isnull(c.notGetQty,0)as notGetQty,isnull(d.notReachQty,0) as notReachQty

from @temp1 a

left join @temp2 b on a.itemid=b.itemid

left join @temp3 c on a.itemid=c.itemid

left join @temp4 d on a.itemid=d.itemid

--未出貨訂單

union all

select '----------------','------------------','------------------','-------------------',null,null,null,null

union all

select '單別','單號','訂單日期','品號',null,null,null,null

union all

select t1.tb01,t1.tb02,t1.tb03,tc04 as itemcode,sum(isnull(tc06,0))-sum(isnull(tc07,0)) as num,null,null,null from coptb t1

left join coptc t2 on t1.tb01+t1.tb02=t2.tc01+t2.tc02

where t1.tb03 >= @start_date and t1.tb03<'1000000' and (t1.tb03<= @end_date or @end_date='') and tc11='N'

group by t1.tb01,t1.tb02,t1.tb03,t2.tc04
分享到:
评论

相关推荐

    SQL复习资料SQL复习资料SQL复习资料SQL复习资料

    SQL Server提供了几个示例数据库,如**AdventureWorks**、**Northwind**和** pubs**,这些数据库包含真实世界的数据,可以帮助学习者实践SQL查询和操作。 在复习时,不仅要掌握这些理论知识,还要通过大量练习来...

    数据结构_复习数据结构_复习

    复习数据结构时,我们需要理解以下几个关键知识点: 1. **数据结构的概念**:数据结构包括数据的逻辑结构、存储结构和数据的操作。逻辑结构是指数据元素之间的关系,如线性结构、树结构和图结构。存储结构则是数据...

    专业课复习经验专业课复习经验专业课复习经验专业课复习经验专业课复习经验专业课复习经验专业课复习经验专业课复习经验专业课复习经验专业课复习经验专业课复习经验专业课复习经验

    在复习过程中,需要注意以下几个方面: - **基本概念**:理解各种数据结构的基础知识,如数组、链表、栈、队列等。 - **算法应用**:掌握基于不同数据结构的典型算法,比如排序算法、查找算法等。 - **实践操作**:...

    《信息管理概论》复习题.pdf

    信息处理过程包括信息的收集、加工、传递和存储等几个方面。 逻辑顺序方法 逻辑顺序方法把信息资源的管理进行划分,包括分类、登记、调查等几个方面。 网络安全功能 网络安全功能主要包括对象认证、数据保密、访问...

    计算机二级ACCESS复习方法

    在准备考试的过程中,以下几个关键知识点和复习策略至关重要。 首先,了解考试大纲是复习的基础。Access 2011的考试大纲涵盖了数据库基础、表的设计与管理、查询、窗体、报表、宏和模块等多个方面。考生需要通读...

    数据库复习资料数据库复习资料

    复习资料中可能涵盖了以下几个重要的知识点: 1. **数据库基本概念**:数据库(Database)是一个组织和存储数据的系统,它能提供数据的创建、查询、更新和删除功能。理解数据库的基本结构,包括关系型数据库和非...

    存储过程及触发器实验报告.pdf

    在实验中,我们首先创建了一个存储过程,用于查询学号为1的学生信息。这涉及到对`Student`表的操作,包括学号、班级编号和姓名。存储过程的创建有助于简化重复的查询操作,提高数据库的效率。 接下来,我们为存储...

    杭电计算机组成原理复习卷

    复习计算机组成原理时,除了上述两点,还应关注以下几个重要主题: 1. **运算器**:理解算术逻辑单元(ALU)的功能,了解不同的数据表示(如二进制、八进制、十六进制、浮点数等)以及运算过程。 2. **寄存器**:...

    数据库期末复习总结大三复习资料.docx

    数据库期末复习总结大三复习资料.docx 本文档总结了数据库管理的基本概念、数据库系统的结构、实体关系模型、数据库设计的基本步骤和规范化理论。 一、数据库管理的基本概念 数据库管理是指对数据的采集、存储、...

    软件工程大二下数据库复习1

    视图是从一个或几个基本表(或视图)导出的一个虚拟表,数据库中只存放视图的定义,而不存放视图对应的数据,这些数据仍然存储在原来的基本表中。 八、E-R 概念模型转换为关系模型 E-R 概念模型转换为关系模型的...

    数据库期末考试复习题库(非常全面)

    数据库期末考试复习题库的知识点可以从以下几个方面来详细阐述: 1. 数据库基础概念 数据库是存储、管理和处理数据的系统。期末考试通常会涉及数据库的基础知识,如数据模型、数据库系统(DBMS)、数据独立性、事务...

    C Primer Plus 附录A 复习题答案

    在C语言的学习中,附录A的复习题涉及了以下几个核心知识点: 1. **基本数据类型**:包括整型(int)、字符型(char)、浮点型(float和double)以及布尔型(_Bool)。理解它们的存储大小、取值范围和使用场景是编程...

    计算机操作系统备考总复习

    进程管理主要涉及以下几个方面: 1. **进程创建与撤销**:当用户启动一个程序时,操作系统会为其创建一个进程。进程撤销发生在程序执行完毕或因异常而终止时。 2. **进程调度**:操作系统通过调度算法(如FCFS、...

    8086 汇编期末复习

    在复习8086汇编时,你需要理解和掌握以下几个核心概念: 1. **汇编语言与高级语言的区别与联系**: - 区别:汇编语言是一种低级编程语言,每条指令都对应于计算机硬件的机器码,而高级语言更接近人类语言,抽象...

    linux 的一些复习资料

    Linux 操作系统具有以下几个特点: 1. 开源:Linux 操作系统的源代码是公开的,任何人都可以免费下载和使用。 2. 免费:Linux 操作系统是免费的,不需要付费购买。 3. 高安全性:Linux 操作系统具有非常高的安全性...

    数据结构复习通.doc

    在这个复习文档中,我们主要关注以下几个核心知识点: 1. **数据结构**:数据结构是一组数据的组织形式,它定义了数据之间的关系和操作集合。它可以是逻辑结构,如数组、链表、树、图等,也可以是存储结构,即在...

    并行计算期末考试复习

    在并行计算期末考试复习中,我们需要理解和掌握以下几个核心知识点。 首先,我们需要了解并行计算的两种基本存储模型:共享存储和分布存储。共享存储系统中,所有的处理器都可以访问相同的全局地址空间,数据在...

    操作系统期末复习大纲可能会包括以下几个主要部分简要总结文档

    操作系统期末复习大纲可能会包括以下几个主要部分: 1. **操作系统概述**:复习操作系统的基本概念、类型(单用户、多用户、实时、网络等)以及其在计算机系统中的作用。 2. **进程管理**:理解进程的创建、调度、...

    关于dataaccess 的复习资料

    数据库访问通常涉及到以下几个关键步骤: 1. **创建Connection对象**:首先需要创建一个Connection对象,它代表与数据库的连接。例如,在使用ADO.NET时,可以通过创建SqlConnection对象来连接到SQL Server数据库。 ...

Global site tag (gtag.js) - Google Analytics