ALTER procedure [dbo].[sp_fy_Re]  
as  
declare @ID int,  
        @state int  declare  cur1 cursor for   
select ID from SugTb where [State]='出仓' and StateNum=1 order by ID 
open cur1  
fetch next from cur1 into  @ID  
while @@FETCH_STATUS=0   
begin  
 exec @state=sp_fy_Bid @ID  
   
 fetch next from cur1 into  @ID  
end  
close cur1  
deallocate  cur1  
  return 0上面的已经查询出来, 
 exec @state=sp_fy_WinBid 中 还可以进行任何操作, 。如果不想在游标中调用另一个存储过程,就把它替换成SQL语句 就行了

解决方案 »

  1.   

    现在有了CTE 等等方法。游标已经不是必须的,可以用别的方式来处理。
    所需要考虑的就是,性能跟可维护性的问题。
      

  2.   

    if object_id('[TB]') is not null drop table [TB]
    create table [TB](ld_P INT,LastName varchar(50),FirstName varchar(50),Address varchar(50),City VARCHAR(50))
    insert into [TB]
    select 1,'1',NULL,NULL,'bvv' union all
    select 2,'4',NULL,NULL,'bvv' union all
    select 3,'8',NULL,NULL,'bvv' union all
    select 4,'12',NULL,NULL,'bvv' union all
    select 5,'22',NULL,NULL,'222'
     
    GO
     select * from [TB]
     go
    DECLARE @str VARCHAR(50)
     ----------------------开始--------------------
    BEGIN TRY
    BEGIN TRAN
        DECLARE test  CURSOR   FOR SELECT  LastName FROM dbo.TB
        OPEN test
     FETCH NEXT FROM test INTO @str
     WHILE (@@fetch_status=0)
      BEGIN
        PRINT   @str  --取出LastName给变量,有这个变量值、添加、删除、更新都可以操作
       FETCH NEXT FROM test INTO @str
      END
        CLOSE test
        DEALLOCATE test
    COMMIT TRAN
    END TRY
    BEGIN CATCH
         IF @@TRANCOUNT > 0
                ROLLBACK TRAN
    END CATCH
     ---------------------结束--------------------
    给你一个例子