Click here to Skip to main content
14,984,271 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to get the total count over selected columns in my table.

I have 45 columns in my table. I need 43 of them summed and totaled for a counter.

I can not seem to get this sql statement to work:
SQL
SELECT SUM([index],[01],[02],...,[at]) FROM [count];

The "..." are the rest of the 43 columns.

Can you help?
Posted
Comments
   
What is the issue? Any errors?

SUM is an aggregate, not a genaric function. I don't know get your final goal, but these are your options:
Simply use addition, to get the sum of specific culumn values. You will get as many rows as your selection gives:
SQL
SELECT [index]+[01]+[02]+...+[at] as [SUM] FROM [count];

You can summarize each column on it's own. You will get one row, with as many values, as many columns you add:
SQL
SELECT SUM([index]), SUM([01]), SUM([02]),...,SUM([at]) FROM [count];

And of course, you can combine these, to get the sum of all:
SQL
SELECT SUM([index]+[01]+[02]+...+[at]) as [SUM] FROM [count];
   
Try SELECT SUM([index]), sum([01]),sum([02]),sum([03]),sum([04])... FROM [count];
   
try like
SQL
SELECT
       (col1+ col2 + .... +coln) as ROWTOTAL 
FROM 
       TABLENAME
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900