views:

189

answers:

4

I have a database which contains some numerical fields; now i want to create another field which displays the sum of one of these fields. How can I create that field? thanks

A: 

You could set up another field which is the result of of a function which calculates the sum sum() function, but this will have performance implications. A better solution maybe to set up a trigger which calculates the sum on insert or update of one of the other fields and then inserts it to the sum field

Sheff
i have a column which contains about 100 numerical values;i only want the sum of these values into an index or a new field
Franky
+2  A: 

You could use a computed column:

ALTER TABLE table
ADD SumColumn AS Column 1 + Column2 + Column3
David M
A: 

SUM() leads to believe that you're talking about aggregate functions.

However, I think, in order for your question to make sense, you are really talking about summing a few values within one record. This assumption migth be wrong, if not, then you might try:

create view vw 
 as select 
   col_1, col_2, col_3, 
   col_1 + col_2 + col_3 as col_sum
from tbl
René Nyffenegger
A: 

Why not define the derived value in a view and select from that?

David Aldridge