Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 417
  • Last Modified:

To know sum of a datwindow column

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
Mehram
Asked:
Mehram
  • 4
  • 4
1 Solution
 
lbushbyCommented:
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
 
MehramAuthor Commented:
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
 
lbushbyCommented:
Sorry, missed a trailing bracket, try:

ldc_credit2 = Dec(tab_main.tabpage_2.dw_tab2.Describe('evaluate("sum(  credit for all )",0)'))
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
MehramAuthor Commented:
Now the error is

"invalid argument to function"
0
 
lbushbyCommented:
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
 
MehramAuthor Commented:
<<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
 
MehramAuthor Commented:
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
 
lbushbyCommented:
Great, glad it worked - 'evaluate' can be a very useful function.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now