F.Kahalaj F.Kahalaj - 4 months ago 30
SQL Question

datediff between 2 asymmetric column from same table

how can i use date difference between two asymmetric row from same table?

from [prin]
where ([realtime] is not null) and ([endtime] is not null and)
order by [realtime]

between end date time and next start date time


Use the DateDiff function to get the difference between two dates. Add the day parameter to get the difference in days.

,datediff (day,[endtime],lead ([realtime]) over (order by [realtime])) as days_endtime_2_next_realtime
FROM [prin]
WHERE ([realtime] is not null) 
AND ([endtime] is not null) 
ORDER BY [realtime]