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
2009-12-14 10:00:37
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
2009-12-14 10:33:30
+2
A:
You could use a computed column:
ALTER TABLE table
ADD SumColumn AS Column 1 + Column2 + Column3
David M
2009-12-14 10:01:46
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
2009-12-14 10:03:59
A:
Why not define the derived value in a view and select from that?
David Aldridge
2009-12-14 11:08:09