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 2000 Forums
 Transact-SQL (2000)
 SQL summing a cross columns

Author  Topic 

glynd
Starting Member

1 Post

Posted - 2005-09-22 : 14:00:03
I have a SQL database and I need to add all of the test scores (kept in separate columns by class name) for each individual. How can I sum all of the test scores in a row not a column. Thanks

MichaelP
Jedi Yak

2489 Posts

Posted - 2005-09-22 : 14:06:14
Do a search or some reading about WITH ROLLUP
That might help ya out.

Michael

<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-09-22 : 16:44:04
I suspect you may wish to read up on normalization:

http://www.datamodel.org/NormalizationRules.html

Sounds like your data is not normalized -- you should not be modelling each class name in different columns, but rather in different rows in your table. A fully normalized database makes SELECT statements and other T-SQL statements much easier, shorter and more efficient.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2005-09-22 : 18:31:21
Have you tried this?

select
Name,
Total_of_Test_Scores = test1 + test2 + test3 + test4
from
MyTable






CODO ERGO SUM
Go to Top of Page

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2005-09-22 : 21:32:18
(Moved to the T-SQL forum.)

===============================================
Creating tomorrow's legacy systems today.
One crisis at a time.
Go to Top of Page
   

- Advertisement -