• 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
  • 相关阅读:
    pycharm 中查找替换功能
    Python中括号的区别及用途
    python:return
    WAMPSERVER 启动不了APACHE原因
    Python为什么如此不同?
    Python初试云雨情
    mariadb 的日志
    MySql 之UUID()
    python 自建爬虫复用简单框架(gevent异步)
    python分布式进程
  • 原文地址:https://www.cnblogs.com/Spinoza/p/10052359.html
Copyright © 2020-2023  润新知