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
 trying to divide totals

Author  Topic 

Dan1228
Starting Member

2 Posts

Posted - 2010-08-16 : 14:30:34
I have the following sql statement and im trying to divide the totals at the bottom but does not work, any recommendations?
SELECT CNSLR# Agency, CNSNAME "Agency Name", OCT, NOV, DEC, JAN,
FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, TOTPD "Total Pd", TOTALL
"Total Allocated", DIFFRN Difference, PERCNT "% Spent" FROM
COUNRPT20
UNION
SELECT 0, 'Totals', SUM(OCT), SUM(NOV), SUM(DEC), SUM(JAN),
SUM(FEB), SUM(MAR), SUM(APR), SUM(MAY), SUM(JUN), SUM(JUL),
SUM(AUG), SUM(SEP), SUM(TOTPD), SUM(TOTALL), SUM(DIFFRN),
SUM(TOTPD)/SUM(TOTALL) FROM COUNRPT20

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-16 : 14:35:31
are you getting an error?

Post the DDL for your table



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Dan1228
Starting Member

2 Posts

Posted - 2010-08-16 : 14:49:01
I'm not getting an error, the result is 0? Is that correct what I am doing with the divide?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-16 : 15:10:38
What does

SELECT COUNT(*) FROM COUNRPT20

Give you?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-17 : 02:57:04
Try

1.0*SUM(TOTPD)/SUM(TOTALL)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -