Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding fields into a field within a row

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
Help!
This is the scenario in my datawindow...
Table GRADE has the ff fields: Name, A, B, C & Total. I need to get the total of A, B, & C then save their sum into the field 'Total' OF THE SAME ROW in the Table. How can I do this? What I have done at the moment is temporarily put the sum into another textbox in my datawindow. But i really need to save it in my field TOTAL of the GRADE table.

thx in advance!

:)
 

In relational databases, it is generally accepted that computed values are not stored in the database itself when they are dependent upon other values in the same row. However, there are rare times when it is necessary or at least advisable to do so.

If you want to store the sum of A, B and C in the Total column you can use an update query.

Update Grade Set Total = A + B + C

Of course, you could insert the value when creating the record. Or you could create a Trigger that updated the Total value whenever a record was inserted or updated.

Or as suggested, you could omit the Total column and recalculate when querying the database.

Select Name, A, B, C, A + B + C As Ttoal
From Grade Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
You could also create a view that calculates the total field and then query on that, so you don't have to recode the calculation each time. Admittedly this calc is trivial but the view concept is really handy and saves time when the calc(s) are not trivial.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top