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

Searching Records

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

    Searching Records

    I have an odd little problem and the answer to it so far has eluded me. Kind of reminds me of one of Tom Cone's old teaser puzzles. (Does he do those anymore?)
    I've tried using several loops, but can't seem to find the correct answer. Maybe someone out there might have a solution.

    I have two tables. One is a list of Employees. The other is a transaction table. In the Transaction table, there are three fields of importance. One is the employee id (Empid) which matches a similar field in Employees. The second field contains clients with whom the employee has worked and the third field is the date the employee worked with the clients.

    There are hundreds of employees. The transaction table has several thousand records at this point with different employees, working with different clients. The question is, how do I produce a list of employees and the clients they have worked for AND the last date they worked for them?

    I tried looping through the transaction table for each employee, but I keep getting doubles of the clients showing up. How can I avoid this and just get a simple list?

    Thanks!

    #2
    Re: Searching Records

    Check out the code below. Run this in AlphaSports. It will give you a list of customers with their last invoice.
    The idea is to sort on the customer and the inverse of the date. As we loop through the records grab the first record for each customer then skip over the next records if the customer_id hasn't changed. As soon as a different id is found drop out of the inner loop and record the next 'first' record.

    Code:
    dim tbl as P
    dim custid as C
    dim output as C
    
    
    tbl = table.open("invoice_header",FILE_RO_SHARED)
    tbl.order("customer_id+invert(cdate(date))")
    tbl.fetch_first()
    
    custid = tbl.customer_id
    output = ""
    
    while .not. tbl.fetch_eof() 
    	output = output + tbl.customer_id+":   "+tbl.invoice_number+" - "+tbl.date + crlf()
    	while tbl.customer_id = custid .and. .not. tbl.fetch_eof() 
    		tbl.fetch_next()
    	end while
    	custid = tbl.customer_id
    end while
    
    msgbox(output)
    tbl.close()
    In order to get last visit for each client per employee you would need to tweek that a bit. Combine the employee and the client in the sort order and the comparison key in the while condition. Somethig like the code below. Obviously you need to adjust the field and table names. I changed the output to a file because I figured it wouldn't fit in a message box.

    Code:
    dim tbl as P
    dim key as C
    dim output as C
    
    
    tbl = table.open("Transaction",FILE_RO_SHARED)
    tbl.order("Emp_id+Client+invert(cdate(date))")
    tbl.fetch_first()
    
    key = tbl.Emp_id + tbl.client
    output = ""
    
    while .not. tbl.fetch_eof() 
    	output = output + tbl.Emp_id+" - "+tbl.Client+" -            "+tbl.date + crlf()
    	while tbl.Emp_id + tbl.client = key .and. .not. tbl.fetch_eof() 
    		tbl.fetch_next()
    	end while
    	key = tbl.Emp_id + tbl.client
    end while
    
    fl = file.create("C:\Emp_by_client_last.txt",FILE_RW_EXCLUSIVE)
    fl.write(output)
    fl.flush()
    fl.close()
    
    tbl.close()
    Tim Kiebert
    Eagle Creek Citrus
    A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

    Comment


      #3
      Re: Searching Records

      And this version only prints the employee once for multiple clients.

      Code:
      dim tbl as P
      dim key as C
      dim emp as C
      dim output as C
      
      
      tbl = table.open("Transaction",FILE_RO_SHARED)
      tbl.order("Emp_id+Client+invert(cdate(date))")
      tbl.fetch_first()
      
      key = tbl.Emp_id + tbl.client
      emp = tbl.Emp_id 
      output = ""
      
      while .not. tbl.fetch_eof() 
      	output = output + ut(tbl.Emp_id ) + crlf() + replicate("-",30) + crlf()
      	while tbl.Emp_id  = emp  .and. .not. tbl.fetch_eof()
      		output = output + tbl.Client + "             " + tbl.date + crlf()
      		while tbl.Emp_id + tbl.client = key .and. .not. tbl.fetch_eof() 
      			tbl.fetch_next()
      		end while
      		tbl.Emp_id + tbl.client
      	end while
      	output = output + replicate("=",30) + crlf() 
      	emp = tbl.Emp_id
      	
      end while
      
      
      'msgbox(output)
      fl = file.create("C:\Emp_by_client_last.txt",FILE_RW_EXCLUSIVE)
      fl.write(output)
      fl.flush()
      fl.close()
      
      tbl.close()

      Of course you could also just copy the relevant records to a temp table and then run reports from there.

      PS Apologies to Prof. Pickypicky for not fully commenting the code.
      Tim Kiebert
      Eagle Creek Citrus
      A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

      Comment


        #4
        Re: Searching Records

        Charles, a brute force approach to get a list of all clients each employee worked with:

        Sort the transaction table by employee + customer + inverted date worked
        Use a script that involves three nested loops.
        Loop through the employees - grab the employee name each time it changes
        .. and for each employee loop through their customers - grab the customer name and date worked each time it changes
        .... and skip the transactions that have the same customer name. i.e. skip til the customer name changes

        Comment


          #5
          Re: Searching Records

          Thanks Tim for the time and effort on this. Makes sense to me what you are doing. I tried several things before resorting to the board. One was to get all the records then eliminate the ones I didn't need by using some form of the duplicate record concept.

          Tom, thanks. I seem to do everything by brute force! I'm always looking for that clever idea I missed!

          Comment


            #6
            Re: Searching Records

            So what happens after you get this list? Do you bill the client for the employees time? Or is this just to see who worked for whom last?

            Just curious...
            Robin

            Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

            Comment


              #7
              Re: Searching Records

              Hi Robin!

              I've created a huge employee time management system, which then turns into an invoicing system. For this client of mine, they have many employees working in home health care. Each employee works for various clients and then sends in their timeslips for the time worked. These are then keypunched and the payroll is then computed. I then "flip" that table around and view it by Client. That way the company can produce invoices for each client. Thus, if a client has one or more employees working there, it is all reflected on the invoice.

              What the manager would like to see, is just who is working for what client during specific times, so he can keep track of what is going on as it is not reflected on the invoice.

              I hope this all makes sense!

              Charlie

              Comment


                #8
                Re: Searching Records

                Thanks Charlie, it makes great sense.
                Robin

                Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

                Comment


                  #9
                  Re: Searching Records

                  Well, if anyone needs to know about time manipulation, let me know. I learned a lot on this project.

                  Comment


                    #10
                    Re: Searching Records

                    Here is my final code. Many thanks to Tim who helped get me on the right track. Sometimes just the discussion of a problem on this board spurs creative thought!

                    Anyway, Tim could not read my mind, but I decided after some study to write this to a table. I then created a set with Employees at the top and this new table as the one-to-many. From there, it was a cinch to create a simple report and format it as I wanted or was required.

                    Here is my final code:
                    Code:
                    dim t as P
                    dim key as C
                    
                    t = table.open("Timehours",FILE_RO_SHARED)
                    t.order("Empno+Conid+invert(cdate(edate))")
                    t.fetch_first()
                    s=table.open("ConsumerIDs")
                    s.zap(.T.)
                    key = t.Empno + t.conid
                    
                    
                    while .not. t.fetch_eof()
                    	 s.enter_begin()
                    	 s.empno=t.empno
                    	 s.conid=t.conid
                    	 s.edate=t.edate
                    	 s.lastfirst=t.lastfirst
                    	 s.consumer=t.consumer
                    	 s.enter_end()
                    	 
                    	while t.Empno + t.conid = key .and. .not. t.fetch_eof() 
                    		t.fetch_next()
                    	end while
                    	key = t.Empno + t.conid
                    end while
                    
                    s.close()
                    t.close()
                    As always, I hope this helps someone else!

                    Comment


                      #11
                      Re: Searching Records

                      Charles,
                      Your welcome, happy to help. Good to hear you got it worked out.

                      Cheers Tim
                      Tim Kiebert
                      Eagle Creek Citrus
                      A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

                      Comment


                        #12
                        Re: Searching Records

                        Thanks to you for without the idea of the loop and index, I never would have gotten it done!

                        Thanks again.

                        Charlie

                        Comment


                          #13
                          Re: Searching Records

                          Or you can build a summary operation that sorts on the employee and client code and gives the max date for work. ie the last date worked.

                          Your results are in a table.
                          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


                            #14
                            Re: Searching Records

                            Originally posted by Al Buchholz View Post
                            Or you can build a summary operation that sorts on the employee and client code and gives the max date for work. ie the last date worked.

                            Your results are in a table.
                            A necessary reminder indeed.

                            Comment

                            Working...
                            X