zoukankan      html  css  js  c++  java
  • T-SQL 带参数存储过程

    创建带参数的存储过程

     1 use StudentManager
     2 go
     3 if exists(select * from sysobjects where name='usp_ScoreQuery4')
     4 drop procedure usp_ScoreQuery4
     5 go
     6 create procedure usp_ScoreQuery4 --创建带参数的存储过程
     7 @AbsentCount int output,--缺考总人数
     8 @FailedCount int output,--不及格总人数
     9 @CSharp int=60,
    10 @DB int=60
    11 as
    12     select Students.StudentId,StudentName,C#=CSharp,DB=SQLServerDB
    13                  from Students
    14                  inner join ScoreList on Students.StudentId=ScoreList.StudentId
    15                  where CSharp<@CSharp or SQLServerDB<@DB        --显示结果列表 
    16     select @AbsentCount=count(*) from Students 
    17                 where StudentId not in(select StudentId from ScoreList) --查询缺考总人数
    18     select @FailedCount=count(*) from ScoreList
    19                  where CSharp<@CSharp or SQLServerDB<@DB      --查询不及格总人数
    20 go

    调用

    1 use StudentManager
    2 go
    3 --调用带参数的存储过程
    4 declare @AbsentCount int,@FailedCount int --首先定义输出参数
    5 exec usp_ScoreQuery4 @AbsentCount output,@FailedCount output
    6 --使用反馈的结果
    7 select 缺考总数=@AbsentCount,不及格总数=@FailedCount

    调用时传入输入参数

    1 use StudentManager
    2 go
    3 --调用带参数的存储过程
    4 declare @AbsentCount int,@FailedCount int --首先定义输出参数
    5 exec usp_ScoreQuery4 @AbsentCount output,@FailedCount output ,65,70
    6 --使用反馈的结果
    7 select 缺考总数=@AbsentCount,不及格总数=@FailedCount
  • 相关阅读:
    mini2440移植uboot 2014.04(四)
    mini2440移植uboot 2014.04(三)
    【这些年】Linux C/C++软件开发用过的工具
    Valgrind的Memcheck快速入门
    《浪潮之巅》读后感
    三层浅析及示例分析
    C语言的代码内存布局详解
    超级立方体小记
    如何和项目经理沟通产品的交付?
    CentOS配置smaba与Windows共享文件
  • 原文地址:https://www.cnblogs.com/Spinoza/p/10052359.html
Copyright © 2011-2022 走看看