I am using SQL Server 2014. I am facing a problem when I want to compare previous row date time with current row in second. The error states:
The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.
SQL Server 2016 solved this issue with DATEDIFF_BIG
but that function is not supported in SQL Server 2014. And currently there are no plans to change database server with SQL Server 2016.
Any alternative solution would be appreciated.
SELECT ROW_NUMBER() OVER (Order by A.MDetailID) as Row
, DATEDIFF(SECOND, A.CreatedDate, LEAD(A.CreatedDate,1,0) OVER (ORDER BY A.CreatedDate))
FROM dbo.tbl_VehicleLiveMovementDetail A