WITH cte AS
(
SELECT [Status] ,
[Date] ,
[Time] ,
Cast([Date] AS DATETIME) + Cast([Time] AS DATETIME) AS [datetime]
FROM @MyTable )
SELECT [Status] ,
[Date] ,
[Time] ,
Cast(Dateadd(minute, Datediff(minute, Lag([datetime]) OVER ( ORDER BY [datetime] ), [datetime]), '00:00:00') AS TIME) AS timedifference
WHERE date BETWEEN '"& DATETIMEPICKER1.VALUE.DATE &"' AND '"& DATETIMEPICKER2.VALUE.DATE &"'
from cte