Distinct in roster

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Distinct in roster

Post by htuser »

Dear Cspro Developer Team and Csprousers,
I would like to know if there's an equivalent of SQL's Select Distinct/Select Group By in Cspro Logic?
Greg informed me months ago how to delete under conditions in Cspro Logic.
Why i need this?
I've a radio button list where enumerators must enter informations/data for each choice in a roster. Some choices may require to enter information in
several rows. Before leaving the roster i would like to have insurance that all related data have been entered.
Since the radio button list come from an array, i already know row number. So if i can compare this with the count select distinct equivalent, i can force enumerators to enter all related data.
C++ already have this, when Cspro support C/C++ or Sqluery supporting Records, items, this will be very easy.
Here's the solution under C++.

Code: Select all

void printDistinct(int arr[], int n) 
{ 
    // Pick all elements one by one 
    for (int i=0; i<n; i++) 
    { 
        // Check if the picked element is already printed 
        int j; 
        for (j=0; j<i; j++) 
           if (arr[i] == arr[j]) 
               break; 
  
        // If not printed earlier, then print it 
        if (i == j) 
          cout << arr[i] << " "; 
    } 
} 
Please let me know about,

Thanks in advance for support.
G.VOLNY, a CSProuser from Haiti, since 2004
aaronw
Posts: 561
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: Distinct in roster

Post by aaronw »

Can you accomplish this by using dynamic value sets, so only valid choices are displayed based on previous responses? Then at the end of the roster you are done instead of having a check and having the enumerator go back and make corrections.
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Distinct in roster

Post by htuser »

Dear Aaron,
Thank you for your support. Since enumerators can use a single modality (response) to fill more than one row (occurrence) it's not a solution to use valid choices that are displayed based on previous responses. My first idea is to count distinct occurrence, maybe you have better than.
Please let me know what's possible in Cspro logic.
The way that i think is to loop through item occurrences and fill an array only with distinct response. After, it will be very easy to count with length or tblrow.
What do you think about?

Thanks in advance,
G.VOLNY, a CSProuser from Haiti, since 2004
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Distinct in roster

Post by Gregory Martin »

If you're trying to count the number of unique values in a group, try something like this:
numeric number_distinct_values = 0;

do numeric counter = 1 while counter <= count(VALUE)

    if seek(VALUE = VALUE(counter)) = counter then
        inc(number_distinct_values);
    endif;

enddo;
For each value in the list, it searches to see where the first instance of that value is found. If it's found on the current value you're processing, then it's a distinct value.
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Distinct in roster

Post by htuser »

Thank you Greg. This is that i need.
And what about the CaseListingFilter issue?
I tried multiples regular expression, with no results.
Best Regards,
G.VOLNY, a CSProuser from Haiti, since 2004
Post Reply