How to use calculated fields

Frequently, in addition to a simple data output, it may be necessary to perform different kinds of data manipulation, such as summation, calculation of simple average, etc.

Let's discuss a few concrete cases by the example of "Cars" table in test MS Access database (examples.mdb) that comes with ASPRunnerPro. Depending on complexity of solving problem you need to make some changes on Events tab, on Edit SQL query tab or on the Visual Editor tab.


1. SQL method. Adding a calculated field which gives us an average of EpaCity and EpaHighway fields

1. Open your project and proceed to Edit SQL Query tab.

2. Switch to the SQL mode.

3. In SQL mode add string ([EPACity] + [EPAHighway])/2 as AvgEpa.

Sample SQL Query

4. Proceed to Choose fields screen.

5. For AvgEpa field unselect following checklists: Add, Edit, Inline Add, Inline Edit.

6. Build your project and view results in browser.

For next two items you should modify your database for a bit. Add to Cars table numeric field Tax. It's important, that this field should be able to hold fractional values (use float or double datatype).


2. Using server side events. Calculating the tax when record is added or edited.

1. Click on Before Record Updated Event.

2. Modify sample event code by putting following code snippets to appropriate place.

ASPRunnerPro Example

PHPRunner Example

ASPRunner.NET Example

3. Apply the same code to Before Record Added Event.


3. Using Javascript to calculate tax on the fly when Price or Horsepower fields are being changed

1. Open your project and proceed to the Events tab.

2. Click on JavaScript Onload event.

3. Add following code:

Now you can edit or add new records and every time when you make changes in Horsepower or Price field correspondingly Tax field has changed. It's very comfortable 'cause right away you see imposed tax and can modify price depending on it.

Applies to:

  • ASPRunnerPro
  • PHPRunner
  • ASPRunner.NET

Back to top