select id from t1 where id>100我要把上面选择出的id,做为下面存储过程中参数@id的使用.exec sp_updateName @id,'testName'如何在这个存储过程中调用多个id呢?
上面例子仅为在此说明使用.

解决方案 »

  1.   

    1 用游标,循环多次调用存储过程
    2 把存储过程改成函数,直接
    select dbo.函数名(id) as result from t1 where id>100
    你看哪个方便
      

  2.   

    declare @id int
    declare cur cursor for select id from t1 where id>100
    open cur
    fetch next from cur into @id
    while @@fetch_status=0
    begin
        exec sp_updateName @id,'testName'
        fetch next from cur into @id
    end
    close cur
    deallocate cur
      

  3.   

    create proc sp_updateName (@id int, @testName varchar(40))
    as
    declare @T table(id int)
    insert @T select id from t1 where id>100
    ...
      

  4.   

    效率要高的话.就在你存储过程实现sp_updateName .减少数据库循环处理.
      

  5.   

    请问:
    create proc sp_updateName (@id int, @testName varchar(40))
    as
    declare @T table(id int)
    insert @T select id from t1 where id>100这种写法,后面如何来操作,我下面的操作,每次只能针对一个ID进行判断和操作的.