how to calculate for non DB field

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

how to calculate for non DB field

Postby amchtwe » Mon Mar 17, 2008 6:15 am

Hi all,

I'm very new to this forum and actually this is my first question.

I got confuse with servoy and I've no idea how to solve it.

My problem is

- one of the column in my table view that is not directly from Database, it is something like amount (quantity * unitprice , which are database fields). I can calculate the amount in table view by using calculation function of dataprovider.

- but i want to display under table view for sum of calculated amount in the table view.

if you have any suggestion pls reply me

S.O.S

Dennis
You see things; and you say "Why?"
But I dream things that never were; and I say "Why not?"
amchtwe
 
Posts: 32
Joined: Wed Feb 06, 2008 7:46 am
Location: BKK

Postby sbutler » Mon Mar 17, 2008 7:14 am

In order to use a Aggregate in Servoy to perform the Sum, the calculation must be stored. To do this, you just need to add a column to that table and name the column the exact same name as the calculation. Then you will be able to create an Aggregate to sum the column and you can display it on your form.

If you can't, or don't want to store that calculation, there are a few more advanced options...
1. You could loop through the calculations and add to a global variable, and then display that global on your form...essentially doing the sum yourself, but that doesn't scale very well, so it generally not recommended.

2. You can use databaseManager.geDataSetByQuery and run a sql query against your databse and have it perform the sum on the calculation. Like,
SELECT SUM(quantity * price) FROM orders
WHERE ordernumber = ?
Then you can again set a global to the result so it can be displayed on your form
Scott Butler
iTech Professionals, Inc.
SAN Partner

Servoy Consulting & Development
Servoy University- Training Videos
Servoy Components- Plugins, Beans, and Web Components
Servoy Guy- Tips & Resources
ServoyForge- Open Source Components
User avatar
sbutler
Servoy Expert
 
Posts: 759
Joined: Sun Jan 08, 2006 7:15 am
Location: Cincinnati, OH

it solve!

Postby amchtwe » Mon Mar 17, 2008 7:39 am

hi goldcougar

thanks for your solution.

its solve my problem.

but in my case i can't add a new column to the table, cos i just a programmer, i'm not a db administrator.

so i used your second option to solve.

thanks indeep

Dennis
You see things; and you say "Why?"
But I dream things that never were; and I say "Why not?"
amchtwe
 
Posts: 32
Joined: Wed Feb 06, 2008 7:46 am
Location: BKK


Return to How To

Who is online

Users browsing this forum: No registered users and 11 guests