Search code examples
axaptamicrosoft-dynamicsdynamics-ax-2012x++

X++ Odd count result


I'm experiencing a really odd result when I do a count in X++, something I've not experienced before. I am performing what I thought was a really simply count query, but I can't seem to get the result I am after.

WMSOrderTrans   orderTrans;
WMSOrderTrans   orderTransChk;
;

select count(RecId) from orderTrans group by shipmentid where orderTrans.inventTransRefId == 'XXXXXX';
info(strFmt('Count is %1', orderTrans.RecId));


while select orderTransChk group by shipmentid where orderTransChk.inventTransRefId == 'XXXXXX' {
    info(strFmt('Shipment is %1', orderTransChk.shipmentId));
}

The data set that I am selecting all have only 1 shipmentid, so the first select I am expecting a count of 1, instead I get 4 (which is how many lines for that transrefid exist). If I change the count from 'RecId' to 'ShipmentId', then instead of the count, I get actual shipmentId. I simply want it to return the count of the records, which is what I believe I've asked it to do.

I really can't see what I am missing.

In the while select, I get what I expect (the shipmentid), only 1 infolog message for the loop. This tells me that the group by with the where clause is working, but it doesn't explain why the first count select statement isn't behaving as I would expect.

For reference, this is AX2012 R1 system.


Solution

  • For anyone who might be interested in knowing my answer, it's tied up with Jeff's response. At the end of the day, I didn't look at data well enough, and the query returned the correct results. I initially thought there were a number of unique shipments, but I was wrong. My expected result was erroneous. There were 4 lines in the file, but the lines were unique for the item, not the shipment. They were all on the same shipment. So really, my own fault, it goes to show that one really needs to look at the data closely.

    Thanks to all that responded, greatly appreciated.