Solved

To know sum of a datwindow column

Posted on 2011-03-15
8
407 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

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. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

734 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