I’d appreciate if someone could help me with this SQL statement. I currently have this:
select sum(datediff(second, [date1], [date2])) from [MyTable] where <condition>
But I need to refine this selection, i.e. if the difference between dates is greater than @MaxDiffSecs then the @MaxDiffSecs should be used for summation instead. I tried looking into the MIN operator but it has only one parameter, where I’d expect at least 2 to get the minimum of.
Well, anyway, thanks in advance. (I guess you can tell that I’m not really efficient at SQL 🙂
This is off the top of my head, not sure if the CASE works inside a
SUMIf that syntax does not work you could use a CTE