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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SUM Syntax Issue

Author  Topic 

Serious Sam
Starting Member

4 Posts

Posted - 2008-06-12 : 15:56:33
I'm trying to craft a query to sum fields that meet a certain criteria, and am having some trouble with the syntax. I need this query to SUM the Time_Spent fields of all ticket numbers that have been completed and return a single value, but right now the query is returning separate values for each different ticket number. This is what I have:

SELECT SUM(Time_Spent) as timespent
FROM Request
WHERE (Completed = 'Complete')
GROUP BY Ticket_Num
HAVING (COUNT(*)>1)

Everything works in the query except the part where it should return a single SUM value. Thanks in advance for the help.

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2008-06-12 : 16:09:43
[code]
SELECT SUM(Time_Spent) as timespent
FROM Request
WHERE (Completed = 'Complete')
--GROUP BY Ticket_Num
HAVING (COUNT(*)>1)
[/code]

Chirag

http://www.chirikworld.com
Go to Top of Page
   

- Advertisement -