info@techdevops.com | 437-991-3573 | Data Engineering Services
TechDevOps.com
Resources Tools Services
Experts in Microsoft SQL Server on Windows, Linux, Containers | Clusters, Always On, FCI | Migrations, Cloud, Performance



Find the DateDiff between separate log records with starttime and endtime
by BF (Principal Consultant; Architecture; Engineering)
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: