Ankush yadav
Ankush yadav

Reputation: 1

How to subtract two columns data for all the rows

I have a table as below

id  pausetime                 resumetime
-----------------------------------------------------
1   2021-09-22 14:21:34.023   2021-09-22 14:25:37.030
2   2021-09-22 14:37:47.810   2021-09-22 14:40:58.817

I want to subtract resumetime from pausetime for all the rows, then add that time so that I can get the total time between resume and pause, number of rows can be different .

How can I do that ?

I tried this

select 
    dbo.TimeDifference(cast(resumetime as time), 
    cast(pausetime as time)

but I have to do it for all the rows.

Please help me out.

Upvotes: 0

Views: 67

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521269

We can use DATEDIFF here along with SUM:

SELECT SUM(DATEDIFF(ss, pausetime, resumetime)) AS total_diff_in_seconds

Upvotes: 1

Related Questions