I like to set the @Debug tinyint variable in my / SP scripts.
By default / set this value to 0 to suppress messages, 1 to display messages.
Then, instead of using PRINT, use:
IF @Debug > 0 RAISERROR( 'Busy doing something...', 0, 1 ) WITH NOWAIT
Using WITH NOWAIT forces the message to be displayed, not just when flushing the output buffer.
As a convention, I use @Debug = 1 for progress reports, @Debug = 2 to enable dynmaic SQL, @Debug = 3 for outputting result sets.
Of course, if you have GO termination terms in your script, the variable method will not work.
source share