XQuery problem - fn:sum

Discussion in 'XML' started by sjurisic@mrxsolutions.com, Mar 17, 2005.

  1. Guest

    Hi All,

    I hope someone could help; I need to query bunch of files in certain
    collection in certain period of time and generate the result;

    1. All files are stored in //Bookkeeping collection

    2. XML file Syntax:

    <?xml version="1.0" encoding="UTF-8"?>
    <bookkeeping date="20050128">
    <Cash>
    <record billed="40" category="Fee" drid="2" index="1" pid="15" qty="1"
    received="20" unitprice="">
    <desc>Adjust 40</desc>
    <bdate>20050130</bdate>
    </record>
    <record billed="40" category="Fee" drid="2" index="1" pid="15" qty="1"
    received="20" unitprice="">
    <desc>OST: Adjust 40</desc>
    <bdate>20050130</bdate>
    </record>
    </Cash>
    <VISA/>
    <Debit/>
    <Master/>
    <AMEX/>
    <Cheque/>
    </bookkeeping>

    3. My query:

    for $b in //bookkeeping
    let $m := $b/VISA/record/@billed
    let $n := $b/VISA/record/@received
    where $b/@date[contains(., '200501')] and $b/VISA/record/@billed > '0'
    return
    <VISA date="{$b/@date}" billed="{sum($m)}" received="{sum($n)}"/>

    4. Current result:

    <VISA date="20050112" billed="128.0" received="128.0"/>
    <VISA date="20050106" billed="400.0" received="400.0"/>
    <VISA date="20050119" billed="60.0" received="60.0"/>
    <VISA date="20050125" billed="256.0" received="256.0"/>
    <VISA date="20050126" billed="100.0" received="100.0"/>
    <VISA date="20050127" billed="60.0" received="60.0"/>
    <VISA date="20050131" billed="40.0" received="40.0"/>
    <VISA date="20050130" billed="115.0" received="115.0"/>

    ------------------------------------------------------------------
    What I need is:

    <VISA billed="3400" received="3400"> - the summary of the above
    results;

    MANY THANKS,

    Sava
     
    , Mar 17, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. amessimon

    problem using xquery and asp.net

    amessimon, Mar 7, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    645
    amessimon
    Mar 9, 2005
  2. Bastian Gorke
    Replies:
    0
    Views:
    466
    Bastian Gorke
    Aug 14, 2003
  3. Bryce (Work)

    Grouping and Sum problem

    Bryce (Work), Sep 30, 2003, in forum: XML
    Replies:
    3
    Views:
    519
    Bryce (Work)
    Oct 1, 2003
  4. cieron
    Replies:
    2
    Views:
    740
    Dimitre Novatchev
    May 16, 2005
  5. Replies:
    0
    Views:
    408
Loading...

Share This Page