Link to home
Start Free TrialLog in
Avatar of Jeff S
Jeff SFlag for United States of America

asked on

RAISERROR WITH NOWAIT

I am using the RAISERROR WITH NOWAIT to view how my queries are executing and how much time is elapsing between individual statement blocks ... (short example below). Is it possible / or has anyone derived a clever way to do time differences between code block sets in the output messages?

Right now I see the time when it starts and ends the block of code; however, I would LOVE to see some type of time elapse after my ending block to know how long it took between Block 1 and Block 2. I hope I am clear enough on my question; however, if I missed anything, let me know.

Sample message

Start Insert of Initial Visits into #Visits  17:33:11
End Insert of Initial Visits into #Visits  17:33:15

What I am desiring to see:

Start Insert of Initial Visits into #Visits  17:33:11
End Insert of Initial Visits into #Visits  17:33:15 (time elapsed 4 seconds)

Example query with the RAISERROR WITH NOWAIT

DECLARE @StartDate DATETIME = '01/01/2017'
DECLARE @EndDate DATETIME = '03/16/2017'
DECLARE @Print VARCHAR(500)

SET @Print = 'Start Insert into Temp table' + ' ' + CONVERT(VARCHAR , GETDATE(),8);
RAISERROR(@Print , 0 , 1) WITH NOWAIT;

CREATE TABLE #Temp (PatientVisitId INT)

INSERT INTO #Temp

SELECT DISTINCT pv.PatientVisitId
FROM PatientVisit pv
WHERE pv.Visit >= @StartDate and pv.Entry < DATEADD(D , 1 , @EndDate)

SET @Print = 'End Insert of Initial Visits into #Temp '+' '+ CONVERT(VARCHAR , GETDATE() , 8);
RAISERROR(@Print , 0 , 1) WITH NOWAIT;
ASKER CERTIFIED SOLUTION
Avatar of chaau
chaau
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jeff S

ASKER

Awesome!! Thanks!!