zoukankan      html  css  js  c++  java
  • 存储过程中调用另一存储过程中的返回值

    代码

    --存储过程1 返回一个值
    create procedure SP1
      
    @returnValue int output
    as
      
    set @returnValue = 1

    --存储过程2 调用存储过程1中的值

    create procedure SP2
    as
      
    Declare @output int
      
    execute SP1 @output output
      
      
    if @output = 1
        
    select 'output = 1'
      
    else
        
    select 'output <> 1'

    附:ADO.NET调用sp返回的值

    代码
    1.获取Return返回值
    //存储过程
    //Create PROCEDURE MYSQL
    //     @a int,
    //     @b int
    //AS
    //     return @a + @b
    //GO
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString());
    conn.Open();
    SqlCommand MyCommand 
    = new SqlCommand("MYSQL", conn);
    MyCommand.CommandType 
    = CommandType.StoredProcedure;
    MyCommand.Parameters.Add(
    new SqlParameter("@a", SqlDbType.Int));
    MyCommand.Parameters[
    "@a"].Value = 10;
    MyCommand.Parameters.Add(
    new SqlParameter("@b", SqlDbType.Int));
    MyCommand.Parameters[
    "@b"].Value = 20;
    MyCommand.Parameters.Add(
    new SqlParameter("@return", SqlDbType.Int));
    MyCommand.Parameters[
    "@return"].Direction = ParameterDirection.ReturnValue;
    MyCommand.ExecuteNonQuery();
    Response.Write(MyCommand.Parameters[
    "@return"].Value.ToString());

    2.获取Output输出参数值
    //存储过程
    //Create PROCEDURE MYSQL
    //     @a int,
    //     @b int,
    //     @c int output
    //AS
    //     Set @c = @a + @b
    //GO
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString());
    conn.Open();
    SqlCommand MyCommand 
    = new SqlCommand("MYSQL", conn);
    MyCommand.CommandType 
    = CommandType.StoredProcedure;
    MyCommand.Parameters.Add(
    new SqlParameter("@a", SqlDbType.Int));
    MyCommand.Parameters[
    "@a"].Value = 20;
    MyCommand.Parameters.Add(
    new SqlParameter("@b", SqlDbType.Int));
    MyCommand.Parameters[
    "@b"].Value = 20;
    MyCommand.Parameters.Add(
    new SqlParameter("@c", SqlDbType.Int));
    MyCommand.Parameters[
    "@c"].Direction = ParameterDirection.Output;
    MyCommand.ExecuteNonQuery();
    Response.Write(MyCommand.Parameters[
    "@c"].Value.ToString());


    本文来自CSDN博客,转载请标明出处:http:
    //blog.csdn.net/mngzilin/archive/2010/01/09/5162859.aspx
  • 相关阅读:
    TestComplete 14 百度网盘下载
    appium 安装
    python 操作yaml文件
    Linux 性能检测常用的10个基本命令
    清除浮动的几种方式及优缺点总结
    css居中布局的几种方式
    css的优先级权重
    移动端1px的边框
    Nuxt.js入门学习
    vue-cli3 中console.log报错
  • 原文地址:https://www.cnblogs.com/icebutterfly/p/1654251.html
Copyright © 2011-2022 走看看