Home Forums SQL Server 2008 SQL Server Newbies Is Calculating time with a single logDateTime Column and unique ID's possible RE: Is Calculating time with a single logDateTime Column and unique ID's possible

  • What version of SQL Server are you using?  SQL 2012 and above have the functions LEAD & LAG which you could use:
    select
        *,
        DATEDIFF(MINUTE, LAG(LogDateTime, 1) OVER (PARTITION BY [ID], [TransactionID] ORDER BY [ID], [TransactionID], LogDateTime), LogDateTime) AS [MinuteCnt]
    from [dbo].[TransLog]

    From here you can GROUP and SUM however you like.

    FYI, the data you provided violates your primary key constraint.