Saturday, February 10, 2018

Tuesday, February 6, 2018

Instant PRINTs

SQL “PRINT” statements getting buffered and not displaying until buffer is flushed with batch is done or gets full.

Using a RAISERROR with severity of 0 and “WITH NOWAIT” will not interrupt the batch, but will immediately display the output.

Here’s an example keeping it to one line and including a timestamp…

--for first msg in batch
DECLARE @msg nvarchar(2044) = convert(varchar(20),current_timestamp,120) + ' - Your First Message Here'; RAISERROR(@msg, 0, 1) WITH NOWAIT;

--for rest of msgs in batch
SET @msg = convert(varchar(20),current_timestamp,120) + ' - Subsequent Messages Here'; RAISERROR(@msg, 0, 1) WITH NOWAIT;