Disable PRINT in SQL Server

I have a script with many debug messages that are printed by the PRINT function. Is there any way to disable these messages? I mean something like SET NOCOUNT ON , but for user messages.

+4
source share
4 answers

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.

+5
source

Sometimes the simplest solution is the best ... Paste all your print statements that are related to debugging as follows:

 PRINT 'Debug ' + [WhateverStatementsYouDesire] 

Then you can search and replace

 PRINT 'Debug ' --> --PRINT 'Debug ' 

Do reverse lookups and replacements to turn them back on ...

(I understand that this is not quite what you asked for, but here is what I am doing now. If there is such a switch that you are looking for, I would probably change this method.)

+3
source

You just need to comment on all your PRINT statements.

+2
source

Quite simple, no. #Debug does not exist either.

the SSMS toolkit has the #debug function, but I have not used it.

+1
source

Source: https://habr.com/ru/post/1315194/


All Articles