One thing that comes up occasionally with SQL Server is the need to write messages to help track the progress of a script. I’m sure most developers have used PRINT statements in a query, to help in debugging by writing values to the Messages tab.
One issue with PRINT is that you won’t see the messages until the script has completed. Which is fine for debugging short scripts, but there are other situations where you may want to see the progress of script.
I ran across this hack:
RAISERROR ('Message', 0, 1) WITH NOWAIT
RAISERROR is normally used to raise an error, but using a severity of 0, the execution of the script won’t stop.
The WITH NOWAIT option will write our message to the screen immediately.
This isn’t something that I’ve used a lot, but it has come in handy a few times when I wanted to track the progress of a script.
Links:
RAISERROR
Mssqltips – Using the NOWAIT option with the SQL Server RAISERROR statement