Solved

To know sum of a datwindow column

Posted on 2011-03-15
8
403 Views
Last Modified: 2013-12-26
PB 10.5

datawindow control dw_1
dataobject dw_salary
sql = "select salary from salary"

I want to know the sum of column "salary"

I can do this by

1) create a compute column "compute_salary"
2) set the expression sum(salary for all) in "compute salary"
decimal ldc_sum_of_salary
ldc_sum_of_salary = dw_1.GetItemDecimal(1,"compute_salary")

My question is
Can I know the sum without creating computed column.

0
Comment
Question by:Mehram
  • 4
  • 4
8 Comments
 
LVL 2

Expert Comment

by:lbushby
ID: 35145988
Assuming you don't want' to change your SQL to 'SELECT SUM(salary)...' then you can use Describe() with an evaluate() expression and a row of zero e.g.

ldc_sum_of_salary = Dec(dw_1.Describe('evaluate("sum(  salary for all )",0)')

0
 

Author Comment

by:Mehram
ID: 35146378
hi lbushby
You have got my point, but there is an error

This is working in my current running application
decimal ldc_credit
ldc_credit = tab_main.tabpage_2.dw_tab2.GetItemDecimal(1,"compute_Credit")

Replacing above technique with the technique in discussion

decimal ldc_credit2
ldc_credit2 = Dec(tab_main.tabpage_2.dw_tab2.Describe('evaluate("sum(  credit for all )",0)')
There is syntax error at compile
0
 
LVL 2

Accepted Solution

by:
lbushby earned 500 total points
ID: 35146968
Sorry, missed a trailing bracket, try:

ldc_credit2 = Dec(tab_main.tabpage_2.dw_tab2.Describe('evaluate("sum(  credit for all )",0)'))
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:Mehram
ID: 35147574
Now the error is

"invalid argument to function"
0
 
LVL 2

Expert Comment

by:lbushby
ID: 35147693
Are you sure that the dataobject contains a column called 'credit'?

In your original post you were using a column called 'salary' - it's important that you use the correct name.

If you're sure that the 'credit' column is there then does creating a computed field in the dataobject with an expression of 'sum(  credit for all )' work or does it give an error as well?
0
 

Author Comment

by:Mehram
ID: 35153788
<<Are you sure that the dataobject contains a column called 'credit'?>>

Sorry, my fault.

the correct column name was amt in one dw and it was to be set in credit column of other (smry dw)

ant yes your code is working exactly I wanted.


// compute credit = sum(amt for all)
ldc_credit = tab_main.tabpage_2.dw_tab2.GetItemDecimal(1,"compute_Credit")
decimal ldc_credit2
ldc_credit2 = dec(tab_main.tabpage_2.dw_tab2.Describe('evaluate("sum(  amt for all )",0)'))
messagebox(string(ldc_credit), string(ldc_credit2))
both message is showing same amount. bingo

I LOVE U!!!

0
 

Author Closing Comment

by:Mehram
ID: 35153794
A new technique is learned and now I can find max value of datawindow column easily which I need most of the time in my application.

Thanx a lot.

Best regards.
0
 
LVL 2

Expert Comment

by:lbushby
ID: 35154705
Great, glad it worked - 'evaluate' can be a very useful function.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question