1.原始表inoutinfo

2.现在想输入时间范围和操作类型输出对应的结果

2.1创建存储过程

create proc selecttype
@type nvarchar(10),@starttime datetime,@endtime datetime
as
select opdt,opemp,optype,num from inoutinfo where optype=@type and opdt between @starttime and @endtime
go

2.2执行存储过程

exec selecttype '入库','2019-01-18 23:15:25.100','2019-01-18 23:15:25.113'

3.现在想输入时间范围查询所有种类的各自操作的数量

3.1修改存储过程

alter proc selecttype
@starttime datetime,@endtime datetime
as
select optype,sum(num) from inoutinfo where opdt between @starttime and @endtime group by optype
go

3.2执行存储过程

exec selecttype '2019-01-18 23:15:25.100','2019-01-19 23:15:25.113'

4.现在想输入查询类型,时间范围输出明细或汇总

4.1修改存储过程

alter proc selecttype
@selecttype nvarchar(10),@type nvarchar(10),@starttime datetime,@endtime datetime
as
if(@selecttype='汇总')
select optype,sum(num) from inoutinfo where opdt between @starttime and @endtime group by optype
else
select opdt,opemp,optype,num from inoutinfo where optype=@type and opdt between @starttime and @endtime
go

4.2执行存储过程

exec selecttype '','消耗','2019-01-18 01:15:25.100','2019-01-19 13:20:25.113'

exec selecttype '汇总','','2019-01-18 01:15:25.100','2019-01-19 13:20:25.113'

MSSQL存储过程应用的更多相关文章

  1. Oracle结果集 (MSSQL存储过程写报表)

    接触SQL Server比较多,写报表是用存储过程实现. 对Oracle实现像MSSQL那样,还是有很多疑问

  2. 托管代码编写mssql存储过程

    参考:http://wenku.it168.com/d_000642903.shtml 打开vs,创建数据库项目,添加新项,选择sql clr c#, 选择存储过程. 样例: [Microsoft.S ...

  3. MSSQL手札三 MSSQL存储过程

    --存储过程完成一段sql代码的封装 create proc trim --参数列表,多个间用逗号分隔 ) as --自定义代码段 ) set @str1=LTRIM(RTRIM(@str)) pri ...

  4. MSSQL存储过程(好久的笔记,翻出来怀念下)

    语法结构: create proc 名称 参数列表 as 代码段 调用: exec 存储过程名称 参数列表 要点: .可以使用output修饰参数 .可以使用默认值,注意需要将最后的参数设置成默认值 ...

  5. MSSQL - 存储过程Return返回值

    1.存储过程中不使用外部参数. 存储过程: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ========================== ...

  6. MSSQL - 存储过程事物

    效果: 创建带有事物的存储过程: use sales --指定数据库 create table bb --创建bb 这个表 ( ID int not null primary key ,--账号 Mo ...

  7. MSSQL - 存储过程OutPut返回值

    1.存储过程中不使用外部参数. 存储过程: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ========================== ...

  8. MSSQL存储过程接收另一个存储过程返回列表

    CREATE TABLE #tmp(m_Meter_ID varchar(20),low_Voltage int,num_Attack int,num_DER int,company_id int,a ...

  9. mssql 存储过程调用另一个存储过程中的结果的方法分享

    转自:http://www.maomao365.com/?p=6801 摘要: 下文将分享"一个存储过程"中如何调用"另一个存储过程的返回结果",并应用到自身的 ...

  10. Delphi调用MSSQL存储过程返回的多个数据集的方法

    varaintf:_Recordset;RecordsAffected:OleVariant; begin ADOStoredProc1.Close;ADOStoredProc1.Open;aintf ...

随机推荐

  1. leetcode记录

    2019 1月31: 141交叉链表, 2月: 2/1: 160环形链表 ,              思路记得,但是指针里面逻辑搞错,这里不是用快慢指针而是同时的指针.:复习了141题还是有问题,把 ...

  2. 第42章:MongoDB-集群--Sharding(分片)--单机的搭建

    ①配置服务器 在大型的集群中,建议配置3台配置服务器,就足够用了.启动配置服务器的方式: 1:先创建几个存放数据的文件夹,比如在前面的dbs下面创建confdb文件夹,然后在confdb下面创建con ...

  3. php,单引号与双引号的区别

    代码示例 <?php $s='666'; $s2="999"; $test = 'name{$s} - {$s2}'; $test2 = "name{$s} - { ...

  4. js中push和pop的用法

    push: 将新元素追加到一个数组中,并返回新的数组长度: 语法:arrayObj.push([item1 [item2 [. . . [itemN ]]]]) var number; var my_ ...

  5. form表单数据进行json转换

    $.fn.serializeJson = function() { var o = {}; var a = this.serializeArray(); $.each(a, function() { ...

  6. Number of subarrays having sum exactly equal to k(explanation for 437. Path Sum III of leetcode)

    https://www.geeksforgeeks.org/number-subarrays-sum-exactly-equal-k/ 讲解的详细 看这道题是为了解决https://leetcode. ...

  7. (转载)Linux之虚拟机 rehl7的ip

    RHEL7最小化安装之后(桥接模式),我们查看本机IP, ip addr 我们要修改配置文件 找到目录 找到文件(每个人的ifcfg-eno16777736都不同),用vi编辑器打开修改配置文件 保存 ...

  8. git 命令(补充篇)的本质理解

    1 标签, git tag tag_name SHA 本质: 在某次commit 上打上标签tag_name ,标签在代码库中起着"锚点"的作用. 注意: commit 由 SHA ...

  9. git 命令(基础篇)的本质理解

    主要命令 1. 提交,git commit 本质:创建一个节点(node),标志了当前位置(node)与以前的node存在不同之处,如下图中的 c0 <-- c1 <-- c2 等等 图中 ...

  10. SpringDataSolr 过滤(或者叫筛选)查询

    // 被本类调用 private Map searchList(Map searchMap) { // 1.1关键字查询 SimpleHighlightQuery highlightQuery = n ...