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

Need help creating complex lookup expression

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

    Need help creating complex lookup expression

    How would I go about creating a table lookup that will return a character value in a field based upon a date value in the current table that is between two date values in the lookup table? For example, the lookup table is quarters and the two date fields are qtrbegdate and qtrenddate. The other table contains transaction records with the date value field called invdate. The field to be filled is QtrID.

    Here's an example. Qtr3 record in quarters table has qtrbegdate of 01-06-03 and qtrenddate of 03-30-03. I need the transactions table to compare the value of the invdate field in the record to the qtrbegdate and qtrenddate fields in the quarters table and return the correct quarter ID value from the quarters table in the QtrID field in the transactions table.

    Any help you all could provide would be GREATLY appreciated. Thanks!!
    Land of the Free, Because of the Brave
    Support our US Military

    #2
    RE: Need help creating complex lookup expression

    Look in the expression function reference book at the lookup function. it should do what you want, here is an example that might help you out.

    invdate = dtoc(transactions->invdate)
    filter = invdate + " >= qtrbegdate .and. " + invdate + "

    Comment


      #3
      RE: Need help creating complex lookup expression

      I tried the dtoc function in my expression but it didn't work. Here's what I came up with that works at the set level field rules but not at the table level:

      IF(INVHEADER->INVDATE>=QUARTERS->Quarterbegdate.AND.INVHEADER->INVDATEQuarterenddate,QUARTERS->Qtryearid,"")

      When I look at the field rule at the table level I see:

      IF(INVHEADER->INVDATE>=LOOKUP("QUARTERS","QTRYEARID="+CHR(34)+QTRYRID+CHR(34),"Quarterbegdate").AND.INVHEADER->INVDATE
      Land of the Free, Because of the Brave
      Support our US Military

      Comment


        #4
        RE: Need help creating complex lookup expression

        JoAnn,

        It sounds to me like you're describing a calculated field rule in the field rules for the transactions table. Once the user enters an InvDate value you want the calc expression to lookup (retrieve) a single value from the Quarters table.

        If this is the right scenario, the approach Raymond suggests is the way to go, but instead of defining variables which are passed to the lookup() function, just pass the raw expressions themselves.

        This would be relatively easy for us to demonstrate for you if you posted a sample data set for us.

        -- tom

        Comment


          #5
          RE: Need help creating complex lookup expression

          Tim, sorry about getting your name wrong. It's funny, you look a bit like Raymond to me.

          -- tom

          Comment


            #6
            RE: Need help creating complex lookup expression

            Yes that is what I'm trying to do. I will zip it up and post it for you to look at. Thanks so much for the help!
            Land of the Free, Because of the Brave
            Support our US Military

            Comment


              #7
              RE: Need help creating complex lookup expression

              Here's a different approach:
              Create an index tag called "FINDQTR" based on the expression
              dtos(qtr_end_date)

              Then the following expression should get what you want:
              lookupc("C",dtos(inv_date),"Qtryearid","Quarters","FINDQTR")
              It's very easy to test this in the interactive window with a variety of different dates.
              As long as you have all the potential quarters filled in properly with the start day of one quarter being one day higher than the end day of the previous quarter, the above should work.

              Comment


                #8
                RE: Need help creating complex lookup expression

                John,

                That looks very promising, and should run faster since it uses the index to do the search. the downside is it requires another indextag. If the Quarters table doesn't have many indextags already it probably won't be noticed since the indextag specification is so simple. -- tom

                Comment


                  #9
                  RE: Need help creating complex lookup expression

                  Tom,
                  I don't think an extra index tag on a table basically used for lookups will matter at all. I usually try to be stingy on indexes on tables that will have a lot of users simultaneously entering and changing records.
                  However, to make queries even faster, they could have a field on the transaction table QTRYEARID that was a calculated field based on the expression:lookupc("C",dtos(inv_date),"Qtryearid","Quarters","FINDQTR")
                  This would work as long as the quarter start dates and end dates weren't changable.
                  John

                  Comment


                    #10
                    RE: Need help creating complex lookup expression

                    Thank you all for the suggestions. I will be testing them today. I am attaching the db for your review and help. Thanks again so much!
                    Land of the Free, Because of the Brave
                    Support our US Military

                    Comment


                      #11
                      RE: Need help creating complex lookup expression

                      John,

                      Your solution finds the correct qtryearid value and puts it in the field, but I get the following error when saving:

                      error: lookup(QUARTERS,QTRYEARID="Q103 ",Quarterbegdate) The system cannot find the path specified.
                      ...\databases\pharminv\quarters.dbf

                      Do I need to put the full path somewhere? Thanks.
                      Land of the Free, Because of the Brave
                      Support our US Military

                      Comment


                        #12
                        RE: Need help creating complex lookup expression

                        This error is not related to anything I suggested. It must be left over from something else you tried.

                        Comment


                          #13
                          RE: Need help creating complex lookup expression

                          JoAnn,

                          After a bit of struggling I was able to implement a lookup() calc field rule in the InvHeader table.

                          I found two things that were making this very difficult for
                          you (and me!):

                          1) the dictionaries for your InvHeader table had become
                          corrupted. There's an empty Validation field rule for the
                          QtrId field that is causing trouble. I dropped the table
                          from the database, deleted the dictionary files (those ending with DDD, DDM, and DDX extensions) and added the table back to the database. This cleared the glitch in table's dictionary files.

                          2) the Lookup() function requires that the filter expression evaluate to a logical true or false value, but that it be written and passed to the function entirely as a character string. The function does not recognize filter expressions which use numeric or date type field values directly. They must be converted to their string equivalents. Doing this requires that you delve into the single area in Alpha Five that remains unfriendly to mortals.

                          Here's the filter expression I developed for the calc field
                          rule for the QuarterId field in the InvHeader table:

                          Code:
                          LOOKUP("Quarters.dbf","dtos(Quarterbegdate) INVDATE)+" ' .and. dtos(QuarterendDate)>= ' " + \
                          DTOS(INVHEADER->INVDATE) + " ')","QtrId")
                          It returns the value of the QtrId field from the Quarters
                          table, if the value of the InvDate field in the InvHeader
                          table falls within the range of QuarterBegDate to
                          QuarterEndDate in the Quarters table.

                          The DTOS() function converts date values into
                          char strings fomratted as YYYYMMDD, which was needed
                          for the comparisons.

                          The apostrophes and quote marks are mysteries to almost all
                          of us. If you want to begin to develop a feel for them study an article at www.learn alpha.com called "Understanding Mysteries of Query Syntax" or some such. The glossary accompanying that piece is worth a second glance, too.

                          To see all this in action, unzip the attachment to an empty
                          folder. Open the default browse or form for the InvHeader
                          table, and change the InvDate in a record, or enter a new
                          record.

                          -- tom

                          Comment

                          Working...
                          X