在一个存储过程中,怎样批量执行另一个存储过程?比如执行一个存储过程 sp_Testexec dbo.sp_Test
@userId=1我想要一个效果,批量执行这个存储过程
比如用户表 UserTable(utid int)我虚幻的效果就是 select (exec dbo.sp_Test @userId=UserTable.utid) from UserTable请问可以吗?或者类似的解决方法

解决方案 »

  1.   

    create function fname(@i int)
    returns int
    as
    begin
    return @i+1
    end
    go
    create table tb(i int)
    insert into tb select 1
    insert into tb select 2
    insert into tb select 3select i,dbo.fname(i) from tb 1 2
    2 3
    3 4
      

  2.   

    你的想法可以在存储过程中实现!你可以定义return 后面的值!不过存储过程的返回值没有函数丰富!除了存储过程外,你可以自己编写个自定义函数!
      

  3.   

    可以把存储过程返回的值,赋值给一个变量如
    create procedure aaa
    as 
    declare @b int 
    select  @b = [id] from Table_1 where id=170
    return @bgo --测试存储过程
    declare @b int
    exec @b= aba
    print @b