I have a script with many debug messages, which are printed by PRINT
function. Is there any way to disable that messages? I have in mind something like SET NOCOUNT ON
, but for user messages.
Select Services. Select Printing. Select General. Remove the check mark from the Print at Power On check box under the Configuration Report option.
When you use SET NOCOUNT ON, the message that indicates the number of rows that are affected by the T-SQL statement is not returned as part of the results. When you use SET NOCOUNT OFF; the count is returned. Using SET NOCOUNT ON can improve performance because network traffic can be reduced.
The SQL PRINT statement serves to display the user-defined message. For example, you are developing a script with T-SQL Loops, and you want to display some specific message on each iteration of a loop. Then you can use the PRINT statement. Or, you can use it when developing a script with conditional statements.
I like to set a variable, @Debug tinyint in my scripts/SPs.
Default/set this to 0 to suppress messages, 1 to show 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 immediately and not just when the output buffer is flushed.
As a convention, I use @Debug = 1 for progress messages, @Debug = 2 to include dynmaic SQL, @Debug = 3 to output result sets.
Of course if you have GO batch terminators in your script the variable method won't work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With