Use the table to store the start and end, also enter the process ID. Then use DATEDIFF () to calculate the elapsed time.
CREATE TABLE Profiling( spid smallint NOT NULL, StartTime DATETIME2 NOT NULL, EndTime DATETIME2 ) INSERT INTO Profiling(spid, StartTime) SELECT @@SPID, CURRENT_TIMESTAMP GO
Trim the table from time to time to avoid spid collisions.
source share