E9.1 SelectKeyedDistinct

FrankCLT

Well Known Member
Can someone explain or give a quick example on the Select, i attempted to use it but didn’t work as I expected.

Thanks,
FrankCLT
 
It effectively does:

Code:
select distinct abalph from F0101 where abat1 = 'E'

In the example above you will get a result set with a unique list of employee names. So if you have five employees named "Brian Oster" your result set will only have one record for "Brian Oster"(as an aside there can be only one anyway, but I digress...).

1. It doesn't appear to work with views or at best you may get unexpected results i.e. doesn't work with JDB_OpenViewExtended even if you select a subset of fields (there is a workaround).
2. To be effective you will need to open your table with a subset of columns, don't open the table with all columns or the full primary key.


Example Code:
Code:
NID        colShipments[] = {NID_SHPN};
struct
{
    MATH_NUMERIC        mnShipmentNumber;
} recShipment={0};

...

if(JDB_OpenTable(hUser, NID_F4941, (ID)0, colShipments,
        (ushort)DIM(colShipments), (JCHAR *)NULL, &hReqShipment) != JDEDB_PASSED

        || JDB_SetSelectionX(hReqShipment, select, nSelIdx, JDEDB_SET_REPLACE) != JDEDB_PASSED

        || JDB_SelectKeyedDistinct(hReqShipment, (ID)0, (void *)NULL, (short)0) != JDEDB_PASSED)
    {
        idReturn = acmeErrorSetTableOpen(lpBhvrCom, lpVoid, (ID)0, NID_F4941);
        goto FunctionCleanUp;
    }

while(JDB_Fetch(hReqShipment, &recShipment, 0) == JDEDB_PASSED)
{
... do stuff ...
}
 
Where are you trying to use it and what were you expecting?
I know Brian has answered but your questions has a 1000 answers :)

Is this table IO or C++ BSFNs etc?

What I will add is if it's table IO ER, wrap your select and then fetch next with an open close.

open table
select table
fetch next table or loop
when done coding
close table
 
Back
Top