Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Fishwagon
Starting Member
10 Posts |
Posted - 2009-10-01 : 09:23:32
|
| Hello,I am using this query to get the amount of time someone spends within a certain action:*******************************SELECT SiteID, StationID, StatsModuleLaunch.ModuleName,CASE SUM( StatsModuleLaunch.EndDateTime - StatsModuleLaunch.StartDateTime )WHEN 0 THEN NULLELSE COUNT( ExternalBatchID ) / SUM( StatsModuleLaunch.EndDateTime - StatsModuleLaunch.StartDateTime ) / 24 ENDAS BatchesPerHourFROM StatsModuleLaunchLEFT JOIN StatsBatchModule ON StatsModuleLaunch.ModuleLaunchID = StatsBatchModule.ModuleLaunchIDWHERE StatsModuleLaunch.EndDateTime IS NOT NULLGROUP BY SiteID, StationID, StatsModuleLaunch.ModuleName*******************************The problem resides in using DATETIME with SUM. Can anyone give me advice as to how to rewrite this query?Thanks!!Thanks and have a great day...Rich |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-10-01 : 09:30:11
|
[code]SELECT sbm.SiteID, sbm.StationID, sml.ModuleName, COUNT(sbm.ExternalBatchID) / (1 + DATEDIFF(DAY, sml.StartDateTime, sml.EndDateTime)) AS BatchesPerHourFROM StatsModuleLaunch AS smlLEFT JOIN StatsBatchModule AS sbm ON sbm.ModuleLaunchID = sml.ModuleLaunchIDWHERE sml.EndDateTime IS NOT NULLGROUP BY sbm.SiteID, sbm.StationID, sml.ModuleName[/code] N 56°04'39.26"E 12°55'05.63" |
 |
|
|
Fishwagon
Starting Member
10 Posts |
Posted - 2009-10-01 : 09:53:07
|
| Thank you Peso, I appreciate it very much. That worked...Thanks and have a great day...Rich |
 |
|
|
|
|
|
|
|