IgO
IgO

Reputation: 133

Print delay in stored procedure

My stored procedure in SQL Server 2008 looks like this:

create PROCEDURE [dbo].[test]
AS
BEGIN
   print 'start'
   waitfor delay '00:02:00'
   print 'end'
END
GO

as intended, in output I want to get:

start

And then after 2 minutes:

end

What should I change?

Upvotes: 1

Views: 586

Answers (1)

Andrey Korneyev
Andrey Korneyev

Reputation: 26876

Instead of print you can use raiserror with nowait and severity level 0.

raiserror('Start', 0, 0) with nowait
waitfor delay '00:02:00'
raiserror('End', 0, 0) with nowait

Severity level below 11 is not treated as exception (in Sql Management Studio it looks like usual print), and with nowait option sends messages immediately to the client.

Upvotes: 4

Related Questions