一个过程a我要在b过程里调用a所返回的值

解决方案 »

  1.   

    create proc a
    as 
    create table #t(....)
    insert into #t
    exec b
      

  2.   

    但是exec b之后,返回的列要固定,如果不定,可能要用其他方法。
      

  3.   

    create table test(id int identity(1,1),code varchar(8)) 
    insert into test select 'aaaa' union select 'bbbb' 
    gocreate procedure sp_test2  
    @id   int        output, 
    @code varchar(8) output 
    as 
    begin 
        select @id=id,@code=code from test where code='aaaa' 
        return 
    end 
    gocreate procedure sp_test1  
    as 
    begin 
        declare @id int,@code varchar(8) 
        exec sp_test2 @id out,@code out    --注意这里
        select @id as nid,@code as ncode 
    end 
    goexec sp_test1 
    go 
    /* 
    nid         ncode     
    ----------- --------  
    1           aaaa 
    */drop procedure sp_test1,sp_test2 
    drop table test
      

  4.   

    Procedure做的是处理数据而不是返回数据,可以处理好数据后把数据放在一张table里让后续程序去调用.
    如果你只是要返回数据应该用function
    http://msdn.microsoft.com/en-us/library/ms191165(v=sql.105).aspx
      

  5.   

    那假设我第一个过程就是select * from table 第二过程如何调用这些数据
      

  6.   

    第一个sp
    if object_id('tmp') is not null
    drop table tmp
    select * into tmp from table第二个sp从tmp表取数操作。
      

  7.   

    create table #TB(XXX TYPENAME)
    insert into #TB(XXX)
    exec ProcName
      

  8.   

    create proc b
    as
    insert into #t select 1create proc a
    as
    create table #t(id int)
    exec b
    select * from #t