Entering calculated results into table

G

Guest

Can I enter the results from a calculation into a field in a table? For
example, if my table has three fields: Price, Cost, and Profit, how can I get
the profit to be calculated and inserted automatically into the Profit Field?
I can do it easily in a query and/or form, but I can't seem to capture the
result in a table. Thanks.
 
R

Rick Brandt

Dennis said:
Can I enter the results from a calculation into a field in a table?
For example, if my table has three fields: Price, Cost, and Profit,
how can I get the profit to be calculated and inserted automatically
into the Profit Field? I can do it easily in a query and/or form, but
I can't seem to capture the result in a table. Thanks.

That's because it doesn't belong in the table. You know how to do it in a query
so use a query. Going through extra steps to push the result into the table is
incorrect thinking in a database application. You store base data and you
"calculate" calculated data when you need it.

This is what computers are good at so let them do it.
 
P

peregenem

Rick said:
it doesn't belong in the table.
incorrect thinking in a database application. You store base data and you
"calculate" calculated data when you need it.

"You are not supposed to put a calculated column in a table in a pure
SQL database ...too bad the real world is not as nice as the
theoretical world. There are many types of calculated columns. The
first are columns which derive their values from outside the database
itself. The most common examples are timestamps, user identifiers, and
other values generated by the system or the application program. This
type of calculated column is fine and presents no problems for the
database... The third type of calculated data uses data in the same
table, but not always in the same row in which it will appear. The
fourth type uses data in the same database. These last two types are
used when the cost of the calculation is higher than the cost of a
simple read. In particular, data warehouses love to have this type of
data in them to save time."

http://www.dbazine.com/ofinterest/oi-articles/celko4
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top