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
 General SQL Server Forums
 New to SQL Server Programming
 Getting one row, not multiple from count

Author  Topic 

sqlbug
Posting Yak Master

201 Posts

Posted - 2010-07-05 : 13:28:34
I have this select returning multiple rows when I need only one.

SELECT CASE WHEN DATA_VALUE >= 0 AND DATA_VALUE < 25.5
THEN (COUNT(DATA_VALUE))*100/(DATEDIFF(day,'1-Jan-2008','31-Dec-2009') + 1)*24 END TheGood,.....
GROUP BY DATA_VALUE,........

Since I am using Count, I need to Group By DATA_VALUE and its returning me many rows. How can I get all the counts in a single row.
Any ideas?
Thanks.

sql-programmers
Posting Yak Master

190 Posts

Posted - 2010-07-05 : 23:42:36
I think you have some other columns in the GROUP BY class, That may be causing problem. Give some sample data.

SQL Server Programmers and Consultants
http://www.sql-programmers.com/
Go to Top of Page

Devart
Posting Yak Master

102 Posts

Posted - 2010-07-06 : 02:34:12
quote:
Originally posted by sql-programmers

I think you have some other columns in the GROUP BY class, That may be causing problem. Give some sample data.

SQL Server Programmers and Consultants
http://www.sql-programmers.com/



Hello,

You can try this:

SELECT
COUNT(CASE WHEN DATA_VALUE >=0 AND DATA_VALUE < 25.5
THEN DATE_VALUE END)*100/(DATEDIFF(day,'1-Jan-2008','31-Dec-2009') + 1)*24 END TheGood
...

But, I don't what your query does. Because this solution may be wrong. Could you describe your problem in detail?

Best regards,

Devart Team
Go to Top of Page
   

- Advertisement -