Disable PRINT in SQL Server

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.

  • SQL. How to insert one select into another select with the ignoring of duplicates and the with changing of Foreign Key in a copy
  • How to convert string data into datetime in SQL Server using dateadd() function
  • SSIS Data Conversion to OLE DB Destination column mapping
  • How to get desired output from this query in sql
  • Converting NULLs to 0 in SQL Pivot
  • Implementation of pagination in coldfusion
  • 4 Solutions collect form web for “Disable PRINT in SQL Server”

    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.

    Sometimes the simplest solution is the best…
    Make all your print statements that deal with debugging as follows:

    PRINT 'Debug ' + [WhateverStatementsYouDesire]
    

    Then you can do a search and replace

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

    Do the opposite Find and Replace to turn them back on again…

    (I do realize this is not quite what you were asking for but here is what I do for now.
    If there is such a switch as you are searching for I would probably change to that method.)

    You need to simply comment out all your PRINT statements

    Quite simply, no. There is no #debug either.

    SSMS tools pack has a #debug feature but I’ve not used it.

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.