Monday, 26 November 2018

MSSQL - Check how many times stored procedure was executed in last 100 seconds


Watch this example on YouTube




Declare @Count int = 0
While (@Count < 100)
Begin
    Begin Try
        Declare @dt DateTime
        Select @dt = dep.last_execution_time
        From sys.dm_exec_procedure_stats as dep inner join
          sys.objects as o on dep.object_id = o.object_id
        Where (dep.last_execution_time >= DateAdd(mi, -1, getdate())) and (o.name = N'spTest')
        Order by dep.last_execution_time desc

        Select 'Executed at: ' + (Convert(varchar(max), @dt, 121))
        Set @Count = @Count + 1
        waitfor delay '00:00:01'
    End Try
    Begin Catch
        print 'Error'
    End Catch
End

No comments:

Post a Comment