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

sort or index on two numeric fields

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

    sort or index on two numeric fields

    Hi all,
    I'd like to sort/create an index using two numeric fields say field1 and field2. I'm looking at spend by vendor and departments within our company so field1 has the total spend from all depts and field2 the individual dept spend. When I create the index using Field1 alone it sorts as expected but when I try and get it to sort firstly by field1 then by field2 it doesn't work. I'm also wanting the highest spend in both cases first.
    Any advice please.

    #2
    RE: sort or index on two numeric fields

    For the 'highest spend in both cases first' try defining the index to sort in descending order. Ascending goes from smallest to largest. Descending, the reverse.

    -- tom

    Comment


      #3
      RE: sort or index on two numeric fields

      Arthur,

      I'd try concatenating the string equivalents of each number, after padding each on the left with zeros.

      If the By_Vendor field contained 1,050.75
      and the By_Dept field contained 525.75

      The resulting index key would look like this:

      "0001050.750000525.75"

      assuming each field was 10 wide.

      In order for the sort sequence to be correct the field width of the string equivalents of each numeric field must be fixed (rigid).

      -- tom

      Comment


        #4
        RE: sort or index on two numeric fields

        Which reinforces the wisdom of the suggestion that unless you intend to perform mathematical computations with the contents of a field, it should be character vs numerical, even if will contain only digits.
        There can be only one.

        Comment


          #5
          RE: sort or index on two numeric fields

          Hi, Stan and Tom. Sadly I did need these as numeric. Can either of you give me a pointer in how to change the two numeric fields in question to enable me to use them for indexing i.e what function do I use. Both fields are 17 in length 15 and two decimal places. An example using Field1 and Field2 would be appreciated.

          Thanks

          Comment


            #6
            RE: sort or index on two numeric fields

            num1=207.86
            num2=195.95

            ?padl(alltrim(str(num1,17,2)),17,"0")+padl(alltrim(str(num2,15,2)),15,"0")
            = "00000000000207.86000000000195.95"

            This is what Tom was referring to only that it is expanded for your widths of 17 an 15. While your fields are those lengths, if you feel that their values would never be so high it may be wise to cut the expression to a shorter width such as what Tom suggested (10 and 10).

            Steve

            Comment


              #7
              RE: sort or index on two numeric fields

              An index on the expression

              padl(alltrim(str(field1,17,2)),17,"0")+padl(alltrim(str(field2,17,2)),17,"0")


              would give you a key value like

              "0000000000001050.750000000000000525.75"

              on padl(alltrim(str(field1,19,2)),19,"0")+" "+padl(alltrim(str(field2,19,2)),19,"0")

              would result in keys like

              "0000000000001050.75 0000000000000525.75"
              There can be only one.

              Comment


                #8
                RE: sort or index on two numeric fields

                Sorry Steve, I usually hit the refresh button before I post if I am diverted from the question for some length of time. Didn't mean to step on your reply.
                There can be only one.

                Comment


                  #9
                  RE: sort or index on two numeric fields

                  Stan

                  And I looked at this thread and thought that it shows you can have a field that only contains numbers be numeric and still use it in a multifield index.

                  Alpha gives the flexibilty not to have to change a number to a character field just because it might be used in an index.
                  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: sort or index on two numeric fields

                    Al,

                    You're right, but the flexibility comes at a cost.

                    Here at least 7 different computations must be done just to derive the index key. Once the key is known Alpha Five still has to figure out where to place it in the index list.

                    In a multi-user setting with moderate data entry needs, this places an additional computation load on the system that I would, personally, try to avoid.

                    -- tom

                    Comment


                      #11
                      RE: sort or index on two numeric fields

                      Tom

                      That also brings up the question of whether this should be an index or just a sort sequence in a report. It all depends on the application and how and when it is used. Is it a report or a form displaying the data?

                      All choices have a cost and a benefit that should be consider by the designer. Having an index that is rarely used is usually a high cost. Omitting a highly usable index can be just as or more costly.

                      I tend to omit indexes until I prove the need for them. It's easier to add something to an application then to take something away from a user, even if it isn't used.
                      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


                        #12
                        RE: sort or index on two numeric fields

                        Thanks to all of you for your responses.
                        This was a one off need and I just wanted to see how it could be done with numeric fields in case I needed that method in the future. I take the point about not using numeric unless a calculation is required.
                        Many thanks again.

                        Comment

                        Working...
                        X