F.Kahalaj F.Kahalaj - 1 year ago 75
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

Answer Source

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] 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download