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
  • 相关阅读:
    完全N叉树寻找祖先
    MySql_Front新建数据库遇到访问地址冲突问题
    C++金额的中文大写
    STL_sort cmp
    螺旋数组
    ~
    Struts向JSP中传值
    Struts1-配置文件部分
    jQuery Ajax 的 load()方式
    jquery animate
  • 原文地址:https://www.cnblogs.com/Spinoza/p/10052359.html
Copyright © 2011-2022 走看看