具体问题是 我要在一个存储过程中 获取另一个存储过程的返回值和输出参数假如有一个这样的存储过程create proc aaaa
@a int ,
@return int  out
select * from a where a.id=@a 
set @return='输入参数'
return 0另一个存储过程create proc  bb
as
 exec  @a =[aaaa]  
这样可以获取到返回值  ... 可怎么获取输入参数呢?

解决方案 »

  1.   

    输出参数--是指定aaaa的结果集么?
      

  2.   

    return值的时候把实际返回值和输入参数通过分隔符一并返回,在bb存储过程里面再拆分
      

  3.   

    use tempdb
    go
    Create table a(ID int identity,num int)
    insert a select 10
    insert a select 20
    gocreate proc aaaa
    @a int ,
    @return nvarchar(100) out
    as
    select * from a where a.id=@a  
    set @return='输入参数'
    goCreate  proc bb
    as
    begin
    declare @return nvarchar(100)--接收返回值 Declare @T table(ID int,Num int)--接收返回结果集 insert @T exec [aaaa] @a=1,@return=@return out select @return as 返回值--返回值  select * from @T--返回结果end
    go
    exec bb
    /*
    返回值ID Num
    1 10
    */
      

  4.   

    return 0--默认情况下就是0,所以这段是没有意义的楼主看看是不是以上结果
      

  5.   

    本帖最后由 roy_88 于 2011-10-16 14:57:06 编辑
      

  6.   

    呵呵第二个参数有一个out没看清楚,向老大学习!
      

  7.   


    谢谢 问题已经解决了....  
    我还想问一个问题 ,那就死 if 语句 里还可以嵌套if语句么  我用了好像会出错呢?
     if 
    begin
    if....
    if....
    if
    begin
    .....
    end
    end
    这样会报错的  好像sqlserver 中有一个关键字  可以在  if里处理批量语句吧..  只要把那批量语句用个关键字 "圈"起来..   麻烦解释下
      

  8.   

    declare @i int
    set @i=4if @i=1
    select 1
    else if @i=2
    select 2
    else if @i=3
    select 3
    else 
    select 4
    goif 中再 ifdeclare @i int
    set @i=3if @i>1
    begin
    if @i<2
    select 1
    else 
    select 3
    end
    else
    select 1
      

  9.   

    不明?没有这样的东西循环可用 if +go /while字符串语句用exec('sql')/sp_executesql 执行
      

  10.   

    每一个段落间,如果使用到了两个及以上的语句,需要使用begin end,例如:if  ...
    begin
       if ...
       begin
          两个及以上语句需要使用begin end
       end
       else
          如果只有一个语句,则可以省略begin end
    end
    else
    begin
       if 
       else
    end
      

  11.   


    当然可以 注意IF的对应和BEGIN...END的对应就可以了