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   --两个参数都是用默认参数
  • 相关阅读:
    字符串算法总结
    [HAOI2007]反素数
    Poj2689 Prime Distance
    [APIO2010]特别行动队
    [国家集训队]middle
    Typecho博客迁移实战
    Typora + 七牛云图床 简易配置
    教你用快捷键 以管理员身份运行cmd
    Typecho博客插入B站视频
    七牛云图床快捷上传方法
  • 原文地址:https://www.cnblogs.com/Spinoza/p/10051258.html
Copyright © 2011-2022 走看看