Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Query to sum total time Expand / Collapse
Posted Monday, January 10, 2011 8:07 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 14, 2015 12:12 PM
Points: 7, Visits: 34
I am having trouble writing a query that will some the total time for an event. I have 2 columns of data, Encounter_Code, Duration. I need the total unique number of Encounter_Code, My code for this part is Count(Encounter_Code) AS Total, and this is working, but when I try and sum the total duration of every event for one Encounter_Code I don't know where to start. Any suggestions?

Post #1045333
Posted Monday, January 10, 2011 9:42 AM



Group: General Forum Members
Last Login: Wednesday, September 23, 2015 3:34 PM
Points: 5,467, Visits: 7,660
Hey Cagan,

Welcome to SSC. It would be easier to help you if you check out the first link in my sig, which will walk you through proving some sample structure and data so that we could write code to show you want you want to do, as well as explaining what said code is doing.

In short, you need two separate statements. One doing the SELECT COUNT ( DISTINCT encounter_number) with no GROUP BY, and another doing a SELECT SUM( DATEDIFF()) FROM tbl GROUP BY Encounter_Number.

- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Post #1045406
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse