Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server Newbies
»
Query to sum total time
Query to sum total time
Rate Topic
Display Mode
Topic Options
Author
Message
cagan
cagan
Posted Monday, January 10, 2011 8:07 AM
Forum Newbie
Group: General Forum Members
Last Login: Wednesday, March 21, 2012 3:34 PM
Points: 7,
Visits: 27
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?
Thanks
Post #1045333
Evil Kraig F
Evil Kraig F
Posted Monday, January 10, 2011 9:42 AM
SSCertifiable
Group: General Forum Members
Last Login: 2 days ago @ 10:09 PM
Points: 5,658,
Visits: 6,100
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 »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.