您好我正在尝试为表中的每个员工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.
答案 0 :(得分: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