Skip to content
Advertisement

Sum the results of a DateDiff [closed]

I have a table with 3 columns: SessionRole (varchar(100)), Start Date (datetime2(7)) and End Date (datetime2(7)). I need to calculate a value that is the sum of End Time – Start Time for all sessions in the table.

The table looks like this:

I was able to get the end time – start time values in this query:

This gives me an output that looks like this:

Now I need to sum those values. I tried adding a sum to this datediff but can’t get it to work. Should this be an inner join with a query (I could not get that to work either). Any direction would be great.

Here is what I tried with sum – just adding the sum in front of the whole datediff:

I get the message: The SUM function requires 1 argument(s).

Advertisement

Answer

You can use CTE :

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement