zoukankan      html  css  js  c++  java
  • T-SQL 有参数存储过程的创建与执行

     1 use StudentManager
     2 go
     3 if exists(select * from sysobjects where name='usp_ScoreQuery2')
     4 drop procedure usp_ScoreQuery2
     5 go
     6 --创建带参数的存储过程
     7 create procedure usp_ScoreQuery2 
     8 @CSharp int,
     9 @DB int
    10 as
    11     select Students.StudentId,StudentName,C#=CSharp,DB=SQLServerDB
    12     from Students
    13     inner join ScoreList on Students.StudentId=ScoreList.StudentId
    14     where CSharp<@CSharp or SQLServerDB<@DB
    15 go
    16 --调用带参数的存储过程
    17 exec usp_ScoreQuery2 60,65 --按照参数顺序赋值
    18 exec usp_ScoreQuery2 @DB=65,@CSharp=60 --参数顺序可以调换

    为参数赋默认值

     1 use StudentManager
     2 go
     3 if exists(select * from sysobjects where name='usp_ScoreQuery3')
     4 drop procedure usp_ScoreQuery3
     5 go
     6 --创建带参数的存储过程
     7 create procedure usp_ScoreQuery3 
     8 @CSharp int=60,
     9 @DB int=60
    10 as
    11     select Students.StudentId,StudentName,C#=CSharp,DB=SQLServerDB
    12     from Students
    13     inner join ScoreList on Students.StudentId=ScoreList.StudentId
    14     where CSharp<@CSharp or SQLServerDB<@DB
    15 go
    16 --调用带参数的存储过程
    17 exec usp_ScoreQuery3 65 --第二个参数没有赋值,则默认
    18 exec usp_ScoreQuery3 @DB=65
    19 exec usp_ScoreQuery3 default,65 --不使用显示方式赋值
    20 exec usp_ScoreQuery3   --两个参数都是用默认参数
  • 相关阅读:
    《计算机网络 自顶向下方法》 第1章 计算机网络和因特网
    记一次代码优化
    不要刻意寻求局部最优解
    Eclipse Jetty插件安装
    Jetty的工作原理
    log4g 使用教程
    有用资料的网址
    Java 编程 订单、支付、退款、发货、退货等编号主动生成类
    Spring框架
    Eclipse常用快捷键大全1
  • 原文地址:https://www.cnblogs.com/Spinoza/p/10051258.html
Copyright © 2011-2022 走看看