Flush Print in SQL Server Query Analyzer

How do I write a message to the Message tab in SQL Server 2005 query analyzer? PRINT statements are all queued up and don’t show up until the entire script is printed. Is there a FLUSH statement of some sort to output the print queue?

There isn’t a flush statement. However, there is an alternative to PRINTing your messages. You can raise an error that isn’t really an error (code of 0) and you’ll get the same effect–your message will be printed immediately.

Here’s the statement:

RAISERROR('Hello World', 0, 1) WITH NOWAIT

Pretty soon, you’ll be raising fake errors all over the place and getting the results you want. Sure, it’s a hack but it works great.

Let me know if it works for you!

One thought on “Flush Print in SQL Server Query Analyzer

  1. Cool! It works great. Just remember to switch to Messages tab in Management Studio to see the messages at real time.

Comments are closed.