Home > SQL Server > SQL Server Print Logging in TSQL / Stored Procedures

SQL Server Print Logging in TSQL / Stored Procedures

In tsql when running stored procedures you may wish to output debug statements.

The problem is that in a long running tsql the “Print” statements will not output until the entire proc has completed.

The solution is to use the RAISERROR statement.

You dont want to raise an error so you call it with a 0 error code, but it has the ability to specify “WITH NOWAIT” which outputs the message straight away.

Combine this with my previous post and you can do this;

set @msg = dbo.udfGetDurationMsg('Task 1', @jobStart, getDate())
RAISERROR(@msg, 0, 0) WITH NOWAIT

which would produce output like:

Task 1 – 0mins 43sec

Cheers
John

Advertisements
Categories: SQL Server
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: