Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# To know sum of a datwindow column

Posted on 2011-03-15
Medium Priority
415 Views
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
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
• 4
• 4

LVL 2

Expert Comment

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

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

lbushby earned 2000 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

Author Comment

ID: 35147574
Now the error is

"invalid argument to function"
0

LVL 2

Expert Comment

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

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

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

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

## Featured Post

Question has a verified solution.

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

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
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 column That will then direct you to their download page. From that p…
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 keystrokes in Netbeans IDE 8.0 for Windows.
###### Suggested Courses
Course of the Month10 days, 19 hours left to enroll