请看下面的代码:
USE [Test]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Test]
AS
BEGIN
begin tran
begin try
SET NOCOUNT ON;
DECLARE @ID int
DECLARE @Count int
set @Count=0
DECLARE Employee_Cursor CURSOR FOR
SELECT id
FROM Person3;
OPEN Employee_Cursor;
FETCH NEXT FROM Employee_Cursor INTO @ID
WHILE @@FETCH_STATUS = 0
BEGIN
WAITFOR DELAY '000:00:01'
SET @Count = @Count+1
Print @Count
FETCH NEXT FROM Employee_Cursor INTO @ID;
END;
commit tran
CLOSE Employee_Cursor;
DEALLOCATE Employee_Cursor;
end try
begin catch
ROLLBACK tran
end catch
END
存储过程运行,然后将以下输出一次全部刷新到客户端(因为在:person3 中有三个记录):
1
2
3
如何在每次游标迭代时将输出刷新到客户端?我正在寻找与 SQL Server 2005 兼容的答案。
我已尝试使用此处描述的 RAISEERROR 语句:如何在 TSQL 中刷新 PRINT 缓冲区?,但是所有语句仍然出现在最后。