How can i calculate datediff (in minutes) between two consecutive rows without using CTE & Temp tables?I was using this successfully, but i need something without CTE and temp tables (both of them are not supported in the tool i am trying to generate a report using custom query).[code="sql"]WITH CTE AS (SELECT ROW_NUMBER() OVER (ORDER BY Id desc) AS RowNo, * FROM MyTable)SELECT t1.*, ISNULL(DATEDIFF(mi, t2.CreateDate, t1.CreateDate), 0) AS DurationFROM CTE t1 LEFT JOIN CTE t2 ON t1.RowNo = t2.RowNo - 1ORDER BY t1.Id desc[/code]
↧