Ok, I have a table that stores information on events. It has a Date field for the day the event takes place and a StartTime and an EndTime field that track when the event starts and ends.
Now, I wrote a simple SQL statement that gives me the total hours for each event by subtracting the StartTime from TheEndTime, and then another statement which adds up these totals. However, my problem is this. When events overlap, I don't want to count the hours for both events over the time where they overlap. I only want to count the hours where one ore more events are occuring, so that there can only be a max of 24 hours, regardless of how many simultaneous events are occuring in the day.
I am really confused at how to represent this in SQL though, and I'm beginning to think that SQL can't handle this sort of calculation and I'm going to have to go through each record programatically. I would really like to avoid doing this though, so if anyone has any suggestions, please let me know. They will be greatly appreciated
Now, I wrote a simple SQL statement that gives me the total hours for each event by subtracting the StartTime from TheEndTime, and then another statement which adds up these totals. However, my problem is this. When events overlap, I don't want to count the hours for both events over the time where they overlap. I only want to count the hours where one ore more events are occuring, so that there can only be a max of 24 hours, regardless of how many simultaneous events are occuring in the day.
I am really confused at how to represent this in SQL though, and I'm beginning to think that SQL can't handle this sort of calculation and I'm going to have to go through each record programatically. I would really like to avoid doing this though, so if anyone has any suggestions, please let me know. They will be greatly appreciated