February 3, 2011 at 3:11 am
Hey all,
I have written a stored proc that goes through a list of items in a loop.
After each loop it uses PRINT to let the user know the result of the loop.
However in Management Studio - i am only seeing the PRINTS at the end of the stored proc. Not as they happen.
I have tried raising errors and get the same result.
Is there any way to get messages to appear during a stored proc - and not just all appear at the end.
TIA
Dan
February 3, 2011 at 12:22 pm
They are buffered and will squirt out when the buffer is full or the process terminates.
If you must have these "messages" received at critical points during a long running procedure you could write them to a service broker message queue where a receiving process on the other end can process them (or print them) as they happen.
The probability of survival is inversely proportional to the angle of arrival.
February 3, 2011 at 12:28 pm
there's an extra option for raiserror so you can get immediate feedback; with nowait, and that shows up immediately in SSMS:
here's an example:
--print error immediately in batch
declare @i int,
@err varchar(100)
--set @i=1
while 0=0
begin
SET @err = 'Progress So Far: Step ' + convert(varchar(30),ISNULL(@i,1)) + ' completed.'
raiserror (@err,0,1) with nowait
waitfor delay '00:00:02'
set @i=ISNULL(@i,1) + 1
end
Lowell
February 3, 2011 at 12:34 pm
If you use RAISERROR and add the WITH NOWAIT directive it'll return results at run time. For example:DECLARE @I INT
SET @i = 0
WHILE @i < 10
BEGIN
RAISERROR(N'Message = %i', 10, 1, @i) WITH NOWAIT
WAITFOR DELAY '00:00:05'
SET @i = @i + 1
END
EDIT: Too slow. 🙁
February 3, 2011 at 12:50 pm
excellent point about the nowait on raiserror fellas, I had forgotten about that feature.
The probability of survival is inversely proportional to the angle of arrival.
February 4, 2011 at 2:34 am
Thanks all - thats perfect.
I am giving a stored proc to run to 3-4 people (who wont need to run it often). I didnt just want them to have to sit there for the 20 mins or so waiting for it to run. They would probably think something had broken and end it.
Thanks again.
Dan
February 4, 2011 at 3:34 am
thanks Lamprey13 for refreshing brain cells with this nice feature of SQL Server
February 4, 2011 at 6:42 am
RAISERROR('Inside loop',0,1)WITH NOWAIT
follow the link to know more about raiserror
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply