info@techdevops.com
TechDevOps.com
Explore Tools
Experts in Microsoft SQL Server Operations, Performance, Migrations, Replication & Cloud



Find the DateDiff between separate log records with starttime and endtime
by BF (Senior MSSQL Operations - Enterprise, Cloud, Strategy)
2015-08-04







Solution:

SELECT t1.LogID, t1.inserteddate, ISNULL(DATEDIFF(s, x.inserteddate, t1.inserteddate), 0) AS Time_Diff_Secs
FROM [dbo].[tbl_name_here] t1
OUTER APPLY (
SELECT TOP 1 inserteddate FROM [dbo].[tbl_name_here] t2 WHERE t2.LogID < t1.LogID ORDER BY t2.LogID DESC) x
where t1.actionname like '%Copy%' and t1.inserteddate > getdate() -7



Image 1: