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. springboot 简单使用 activemq 接收消息

    1.在pom.xml 加入配置文件 <dependency> <groupId>org.springframework.boot</groupId> <art ...

  2. Codeforces Round #536 (Div. 2) E dp + set

    https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_ ...

  3. spring生命周期流程图

    Spring作为当前Java最流行.最强大的轻量级框架,受到了程序员的热烈欢迎.准确的了解Spring Bean的生命周期是非常必要的.我们通常使用ApplicationContext作为Spring ...

  4. PMP:1.引论

    全球项目管理业界定义的最重要的价值 观是责任.尊重.公正和诚实(成功准则).   项目是为创造独特的产品.服务或成果而进行的临时性工作:   开展项目是为了通过可交付成果达成目标.目标指的是工作所指向 ...

  5. 8.AOP全自动

    CGLIB字节码增强 l没有接口,只有实现类. 采用字节码增强框架 cglib,在运行时 创建目标类的子类,从而对目标类进行增强. 导入jar包: 自己导包(了解): 核心:hibernate-dis ...

  6. 使用ILMerge 打包C# 绿色免安装版程序

    使用ILMerge工具,将C#项目debug目录下的exe及其依赖的dll文件打包成一个exe文件,直接双击就可运行. 使用工具: ILMerge :http://www.microsoft.com/ ...

  7. react中使用阿里Viser图表

    参考demo的codesandbox:https://codesandbox.io/s/kxxxx3w5kv 使用步骤:   1. 安装依赖  viser-react和@antv/data-set 2 ...

  8. jQuery的JS库在本地运行项目时提示无法加载

    最近公司有个项目在我本地运行时引用本地的jquery.js,浏览器提示无法加载 <script src="/js/newperson/jquery-1.11.3.min.js" ...

  9. Failed to acquire lock on file .lock in /tmp/kafka-logs. A Kafka instance in another process or thread is using this directory.

    1. 问题现象 启动 kafka 时报错:Failed to acquire lock on file .lock in /tmp/kafka-logs. A Kafka instance in an ...

  10. 2D转换与3D转换的区别

    2D与3D的区别——2D 转换元素能够改变元素 x 和 y 轴.3D 转换元素还能改变其 Z 轴.