我有一个简单的查询循环,我想在执行期间看到PRINT消息。查询是这样的:
WHILE 1 = 1
BEGIN
WAITFOR DELAY '000:00:10'
PRINT 'here'
END
PRINT'here'在我停止进程之前不会输出,但是,我想在运行时看到它。这可能吗?
答案 0 :(得分:22)
您可以使用严重性为0的RAISERROR和NOWAIT选项
WHILE 1 = 1
BEGIN
WAITFOR DELAY '000:00:10'
RAISERROR ('here', 0, 1) WITH NOWAIT
END
答案 1 :(得分:16)
答案 2 :(得分:2)
试试这个..
DECLARE @i INT = 1
WHILE ( @i <= 10)
BEGIN
--- do something
SELECT 'Completed ' + CAST(@i AS VARCHAR(50)) + ' : ' + CAST(GETDATE() AS VARCHAR(50));
SET @i = @i + 1
END