4

嗨,我正在尝试循环查找表中的每个员工 ID。

BEGIN
declare @empId nvarchar(50)
declare cur Cursor LOCAL for
select EmpId from EmployeeMaster 
open cur
fetch next from cur into @empId
     while @@FETCH_STATUS =0     
      begin      
       select  @empId  
      end   
close cur
END

这是我在存储过程中的查询。这有什么问题?它在无限循环中给了我第一个员工 ID。如果我在@@FETCH_STATUS =1 时检查,则没有给出输出。只是说 Command(s) completed successfully.

4

1 回答 1

6

您需要fetch在选择后添加命令

BEGIN
declare @empId nvarchar(50)
declare cur Cursor LOCAL for
select EmpId from EmployeeMaster 
open cur
fetch next from cur into @empId
     while @@FETCH_STATUS =0     
      begin      
       select  @empId  
       fetch next from cur into @empId
      end   
close cur
END
于 2013-07-10T10:52:06.397 回答