This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing the use of RAISEERROR WITH NOWAIT option of SQL Server which uses for printing the messages and errors while execution of Stored Procedure or any Code block.
Using SSMS Debug utility, you can debug your code, but still, developers are liked to debug the code manually by printing the inline messages.
If you are using the only PRINT command for debugging, you can’t get the PRINT result while execution.
Additionally, you can add RAISEERROR WITH NOWAIT which returns the message while execution.
Check few samples:
Code with only PRINT:
You can get all PRINT results after completion of LOOP.
1 2 3 4 5 6 7 8 9 10 |
DECLARE @Count INT SET @Count = 1 WHILE @COUNT <= 5 BEGIN PRINT @Count SET @Count = @Count + 1 WAITFOR DELAY '00:00:05' END |
Code with RAISEERROR WITH NOWAIT:
While execution, you can get the result of PRINT.
1 2 3 4 5 6 7 8 9 10 11 |
DECLARE @Count INT SET @Count = 1 WHILE @COUNT <= 5 BEGIN PRINT @Count SET @Count = @Count + 1 RAISERROR (N'' , 0, 1) WITH NOWAIT WAITFOR DELAY '00:00:05' END |
Stored Procedure with RAISEERROR WITH NOWAIT:
While execution, you can get the result of PRINT.
1 2 3 4 5 6 7 8 9 |
CREATE PROCEDURE usp_GetData AS PRINT 'Debug.....' RAISERROR (N'' , 0, 1) WITH NOWAIT WAITFOR DELAY '00:00:05' GO EXEC usp_GetData GO |
Leave a Reply