webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

How to apply aggregation function sum() on attribute

  • 1.  How to apply aggregation function sum() on attribute

    Posted Mon April 02, 2007 08:34 PM

    I want to sum up all the attribute value. I have tried the following query but it doesn’t work.

    for $i in input()/bank/client/account/depositor
    return sum({data($i/@amount)})

    the output is:
    sum(100)
    sum(500)
    sum(240)

    My expected output is 840

    Can anyone help me?


    #API-Management
    #webMethods
    #Tamino


  • 2.  RE: How to apply aggregation function sum() on attribute

    Posted Tue April 03, 2007 01:46 PM

    The result you are getting is because you are summing each resulting document from the ‘for’ so the result is correct. To get a sum of all @amount attributes you need to reformulate the query thus:

    let $values := (for $doc in input()/bank return xs:integer($doc/client/account/depositor/@amount))
    return xs:integer(sum($values))

    This way the sum function operates on a array of integer values and returns an integer result.

    Hope this helps.


    #API-Management
    #webMethods
    #Tamino