Count kinds of entries

suspectsuspect Member Posts: 16
I would like to count different kinds of entries in a table:

If there are Fields X and Y:

X Y
1 A
2 A
3 B
4 B
5 B

The Sum must be "2" (Two different Values in Y)

X Y

1 A
2 A
3 B
4 C
5 A

Them Sum must be "3" (Three different Values in Y)

Understand? Any ideas?????? Thanks a lot! :D

Answers

  • krikikriki Member, Moderator Posts: 9,115
    There is no direct way to do it:
    You need to create a temptable in which you keep each value.
    Then you have to scan the table and add a counter to the record in the temptable. I give an example for the no. of items in all item ledger entries:

    recItemLedgerEntry is a record on table "Item Ledger Entry"
    tmpItem is a TEMPORARY record on table "Item"
    tmpItem.RESET;
    tmpItem.DELETEALL(FALSE);
    
    recItemLedgerEntry.RESET;
    IF recItemLedgerEntry.FINDSET THEN
      REPEAT
        IF NOT tmpItem.GET(recItemLedgerEntry."Item No.") THEN BEGIN
          CLEAR(tmpItem);
          tmpItem."No." := recItemLedgerEntry."Item No.";
          tmpItem.INSERT(FALSE);
        END;
      UNTIL recItemLedgerEntry.NEXT = 0;
    
    tmpItem.RESET;
    MESSAGE('There are "%1" different items in the Item Ledger Entries",tmpItem.COUNT);
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • suspectsuspect Member Posts: 16
    Yeah, got it.. Thanks!!!!
Sign In or Register to comment.