CREATE proc TA
as
select * from Table_A
GOcreate proc TB
as
--如何在这里调用 TA,
--并对返回的数据进行处理
--比如说把产品的单位从千克 转换成吨
GO

解决方案 »

  1.   

    if object_id('pro1') is not null
          drop proc pro1
    if object_id('pro2') is not null
          drop proc pro2
    if object_id('tbtest') is not null
          drop table tbtest
    GO
    create table tbtest(id int identity(1,1),name varchar(20))
    insert tbtest(name) 
    select 'x' union all
    select 'myname' union all
    select 'myname' union all
    select 'yourname' union all
    select 'myname'
    select * from tbtest
    GO
    ----创建存储过程1
    create proc pro1 @a varchar(16) = null,@returnvalue int=null output
    as
          select @returnvalue = max(id) from tbtest where name = @a
    GO
    ----创建存储过程2(在该存储过程中调用存储过程1)
    create proc pro2 @cmd nvarchar(4000)
    as
    declare @r int
          set @r = 0
          exec sp_executesql @cmd,N'@r int output',@r output
          select @r
    GO----调用存储过程2
    declare @cmd Nvarchar(4000)
    --set @cmd = 'exec pro1 ''myname'',@r output'
    set @cmd = 'exec pro1 @a=''myname'',@returnvalue=@r output'--效果同上一条语句
    exec pro2 @cmd----清除测试环境
    drop proc pro1,pro2
    drop table tbtest
      

  2.   

    也可以将存储过程返回的结果集存入一个表中
    create table #t(...)
    insert into #t exec 存储过程名
    select * from #t
    drop table #t
      

  3.   

    TO   gc_ding(E.T)
    好象你返回的只是一个字段吧
    要是返回的多条记录怎么接收
      

  4.   

    CREATE proc TA
    as
    select * from Table_A
    GOcreate proc TB
    as
    --定义返回的表结构(结构和存储过程A返回值一致)
    insert into # exec proc TA
    --操作 # 表
    --比如说把产品的单位从千克 转换成吨GO
      

  5.   

    TO  gc_ding(E.T)
    按照第二钟方法
    create table #t(...)
    insert into #t exec 存储过程名
    select * from #t
    drop table #t我怎么对从 exec 存储过程名
    得到的数据进行一条一条处理呢
      

  6.   

    谢谢 gc_ding(E.T)  和 zlp321002(风中有只可爱的熊)
    我现在还不懂的就是
    怎么在存储过程里对表里数据进行处理的问题了
      

  7.   

    处理就转换下啊.
    比如:
    类似:(单位转换)
    select a,[b(吨)]=b/1000 from #
      

  8.   

    如果还要放进另一个临时表,可以这样:
    select a,round(b/1000,2) b into #tmp from #