Solved

To know sum of a datwindow column

Posted on 2011-03-15
8
397 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
 

Author Comment

by:Mehram
ID: 35147574
Now the error is

"invalid argument to function"
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now