Search code examples
duplicatesfieldaxaptax++dynamics-ax-2012

How can I find the values in a table that occur more than once?


I have a table with some fields that have the same value in more than one record. I want to get these values that occur more than once.

So far I tried to use the following code to write the field values to the infolog. But this implementation writes all values, not just the ones that occur more than once:

while select myTable
{
    info(strFmt("%1" ,  myTable.getFieldValue("myFieldName") )) ;
}

How could I change this implementation to only get the values that occur more than once?


Solution

  • Not sure if I fully understand your question, but this may help you:

    static void test(Args _args)
    {
        InventTable inventTable;
        ;
        while select count(RecId) from inventTable 
            group by InventTable.ItemType
        {
            info(strFmt("%1 - %2" ,  inventTable.getFieldValue("ItemType"), inventTable.getFieldValue("RecId"))) ;
        }
    }