Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

DBSum() Question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    DBSum() Question

    I am trying to use DBsum to total a range of records, and can't figure out the syntax.
    The context: a Sales table with 3 fields: Date, ProdId (possible values: A, B, C,... R), Amount. The calc field using DBSum() is on a layout that is based on a dummy table
    Q1) How do you use DBSum total all records. I tried DBSum("Sales", "ProdId", .T., "Amount") but always returns zero.
    Q2) How do you use DBSum() to total a range of records, like all records where ProdId is D to M? I created a filtered index ProdId_x with the filter Between(ProdID, "D","M") but don't know how to use it in the DBSum(): DBSum("Sales", "ProdId_x", ???????, "Amount").

    I am aware that all this can be done using Tablesum(), just trying to learn more about DBSum().

    #2
    Re: DBSum() Question

    Not possible, at least per the documentation:

    DBSUM() searches the specified Lookup_Table for one or more records with the specified Key_Value, and returns the sum of the values contained in Lookup_Expression.
    You're trying to supply a range of key_values to the function. It's looking for only one.

    Comment


      #3
      Re: DBSum() Question

      I have always used it with 1 value and checked the help file a few times. I thought I would check with the experts to see if this was possible. Thanks Tom.

      Comment


        #4
        Re: DBSum() Question

        Originally posted by gaby_h View Post
        I tried DBSum("Sales", "ProdId", .T., "Amount") but always returns zero.
        Should be:
        DBSum("Sales", "ProdId", ".T.", "Amount")


        Originally posted by gaby_h View Post
        Q2) How do you use DBSum() to total a range of records, like all records where ProdId is D to M? I created a filtered index ProdId_x with the filter Between(ProdID, "D","M") but don't know how to use it in the DBSum(): DBSum("Sales", "ProdId_x", ???????, "Amount").
        DBSum("Sales", "ProdId", "prodid>='D'.and.prodid<='M'", "Amount")
        Or, among many other ways to do this, you could also say:
        filter="prodid>='D'.and.prodid<='M'"
        DBSum("Sales", "ProdId", filter, "Amount")
        That is if you are working with a script or a UDF, not in an expression.

        Comment


          #5
          Re: DBSum() Question

          edited - too ugly of a format...
          Al Buchholz
          Bookwood Systems, LTD
          Weekly QReportBuilder Webinars Thursday 1 pm CST

          Occam's Razor - KISS
          Normalize till it hurts - De-normalize till it works.
          Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
          When we triage a problem it is much easier to read sample systems than to read a mind.
          "Make it as simple as possible, but not simpler."
          Albert Einstein

          http://www.iadn.com/images/media/iadn_member.png

          Comment


            #6
            Re: DBSum() Question

            Really having a good posting day.... not...
            Last edited by Al Buchholz; 10-15-2009, 07:45 PM.
            Al Buchholz
            Bookwood Systems, LTD
            Weekly QReportBuilder Webinars Thursday 1 pm CST

            Occam's Razor - KISS
            Normalize till it hurts - De-normalize till it works.
            Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
            When we triage a problem it is much easier to read sample systems than to read a mind.
            "Make it as simple as possible, but not simpler."
            Albert Einstein

            http://www.iadn.com/images/media/iadn_member.png

            Comment


              #7
              Re: DBSum() Question

              Gaby


              Like Tom said, in a DB it's a value for an index based process rather than a filter (like a TABLE function).



              DBSUM()

              In a tablesum, you can use a filter.

              TABLESUM()

              An interesting page comparing table and db functions.

              There is a reason that there both functions. Each does a job well, but it's not the same job.

              DB - requires an index and works on one index value.

              TABLE - doesn't require an index and can filter. LQO can apply.
              Al Buchholz
              Bookwood Systems, LTD
              Weekly QReportBuilder Webinars Thursday 1 pm CST

              Occam's Razor - KISS
              Normalize till it hurts - De-normalize till it works.
              Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
              When we triage a problem it is much easier to read sample systems than to read a mind.
              "Make it as simple as possible, but not simpler."
              Albert Einstein

              http://www.iadn.com/images/media/iadn_member.png

              Comment


                #8
                Re: DBSum() Question

                No.. I am having a bad posting day. It is an index BUT..
                You can create an index using the above filter in the index itself. So, all id well.

                Comment


                  #9
                  Re: DBSum() Question

                  Originally posted by G Gabriel View Post
                  No.. I am having a bad posting day. It is an index BUT..
                  You can create an index using the above filter in the index itself. So, all id well.
                  Not much experience with a dynamic filter in an index. Seems it would take some evaluation time as it's ready through the records.

                  But like all things, what are the performance results and differences?
                  Al Buchholz
                  Bookwood Systems, LTD
                  Weekly QReportBuilder Webinars Thursday 1 pm CST

                  Occam's Razor - KISS
                  Normalize till it hurts - De-normalize till it works.
                  Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
                  When we triage a problem it is much easier to read sample systems than to read a mind.
                  "Make it as simple as possible, but not simpler."
                  Albert Einstein

                  http://www.iadn.com/images/media/iadn_member.png

                  Comment


                    #10
                    Re: DBSum() Question

                    Thanks guys for clarifying further. It's just that with the help of board members I used DBsum a few days ago (see my previous post) to solve my trended report issue and was amazed at its speed and was trying to use it wherever I can (typical apprentice mistake). The experienced know what tool to use and when.

                    Comment


                      #11
                      Re: DBSum() Question

                      Q1) How do you use DBSum total all records. I tried DBSum("Sales", "ProdId", .T., "Amount") but always returns zero.
                      Q2) How do you use DBSum() to total a range of records, like all records where ProdId is D to M?
                      1) Add a logical field (named "every") to the table. Don't populate it. Index it, tagname "all".

                      DBSum("Sales", "All", .F., "Amount")


                      2) DBSum("Sales", "All", .F., "if(between(prodid,\"D\",\"M\",Amount,0)")

                      Haven't tried it yet but conceptually it should do what you want.

                      Seem to work in AlphaSports.
                      Code:
                      ? dbsum("customer","all",.f.,"creditrating")
                      = 135
                      
                      ? dbsum("customer","all",.f.,"if(between(left(lastname,1),\"A\",\"F\"),creditrating,0)")
                      = 39
                      Last edited by Stan Mathews; 10-15-2009, 11:17 PM.
                      There can be only one.

                      Comment


                        #12
                        Re: DBSum() Question

                        Thanks Stan, it's past my bed time; it's 1st on my todo list for this week end (v.busy day tomorrow).

                        Comment


                          #13
                          Re: DBSum() Question

                          Stan, would be interested to know if your idea results in any speed increase over tablesum(). I'd think there wouldn't be much gain, if any, since all records have to be evaluated. It might even be slower. --- tom

                          Comment


                            #14
                            Re: DBSum() Question

                            Table ws01ttl with 319736 records. Dbsum() with no calculation expression in the lookup expression.

                            Code:
                            for i = 1 to 20;st = now();? tablesum("ws01ttl",".t.","total_f64");nd = now();? alltrim(str(nd-st,12,5));next i
                            1938574.130000
                            5.46800
                            1938574.130000
                            5.48500
                            1938574.130000
                            5.46800
                            1938574.130000
                            5.48500
                            1938574.130000
                            5.46800
                            1938574.130000
                            5.48500
                            1938574.130000
                            5.46800
                            1938574.130000
                            5.46900
                            1938574.130000
                            5.48400
                            1938574.130000
                            5.51600
                            1938574.130000
                            5.48400
                            1938574.130000
                            5.46900
                            1938574.130000
                            5.48400
                            1938574.130000
                            5.46900
                            1938574.130000
                            5.46900
                            1938574.130000
                            5.46800
                            1938574.130000
                            5.48500
                            1938574.130000
                            5.70300
                            1938574.130000
                            5.46800
                            1938574.130000
                            5.46900
                            
                            
                            
                            for i = 1 to 20;st = now();? dbsum("ws01ttl","all",.F.,"total_f64");nd = now();? alltrim(str(nd-st,12,5));next i
                            1938574.130000
                            4.37500
                            1938574.130000
                            4.43700
                            1938574.130000
                            4.37500
                            1938574.130000
                            4.37500
                            1938574.130000
                            4.37500
                            1938574.130000
                            4.39100
                            1938574.130000
                            4.35900
                            1938574.130000
                            4.37500
                            1938574.130000
                            4.37500
                            1938574.130000
                            4.37500
                            1938574.130000
                            4.39100
                            1938574.130000
                            4.35900
                            1938574.130000
                            4.37500
                            1938574.130000
                            4.37500
                            1938574.130000
                            4.35900
                            1938574.130000
                            4.37500
                            1938574.130000
                            4.35900
                            1938574.130000
                            4.39100
                            1938574.130000
                            4.35900
                            1938574.130000
                            4.39100
                            There can be only one.

                            Comment


                              #15
                              Re: DBSum() Question

                              Same table. Tablesum() with filter on an indexed field (uses lqo?) and dbsum() using calculation in lookup expression.

                              Code:
                              for i = 1 to 20;st = now();? tablesum("ws01ttl","f1056 = '001'","total_f64");nd = now();? alltrim(str(nd-st,12,5));next i
                              65464.210000
                              0.39100
                              65464.210000
                              0.35900
                              65464.210000
                              0.34400
                              65464.210000
                              0.35900
                              65464.210000
                              0.35900
                              65464.210000
                              0.36000
                              65464.210000
                              0.35900
                              65464.210000
                              0.34400
                              65464.210000
                              0.35900
                              65464.210000
                              0.34400
                              65464.210000
                              0.34400
                              65464.210000
                              0.35900
                              65464.210000
                              0.34400
                              65464.210000
                              0.34400
                              65464.210000
                              0.43700
                              65464.210000
                              0.34400
                              65464.210000
                              0.34400
                              65464.210000
                              0.34300
                              65464.210000
                              0.32800
                              65464.210000
                              0.32900
                              
                              
                              
                              for i = 1 to 20;st = now();? dbsum("ws01ttl","all",.F.,"if(f1056 = '001',total_f64,0)");nd = now();? alltrim(str(nd-st,12,5));next i
                              65464.210000
                              4.98400
                              65464.210000
                              4.96900
                              65464.210000
                              4.98400
                              65464.210000
                              4.96900
                              65464.210000
                              4.98400
                              65464.210000
                              4.96900
                              65464.210000
                              4.98400
                              65464.210000
                              4.96900
                              65464.210000
                              4.96800
                              65464.210000
                              4.96900
                              65464.210000
                              4.98400
                              65464.210000
                              4.96900
                              65464.210000
                              4.95300
                              65464.210000
                              4.96900
                              65464.210000
                              4.96900
                              65464.210000
                              4.96800
                              65464.210000
                              4.95300
                              65464.210000
                              4.98400
                              65464.210000
                              4.95300
                              65464.210000
                              4.98500
                              There can be only one.

                              Comment

                              Working...
                              X