Question : Grouping by pallet#

I have my select as follows in the code below, but a olxpal can have multople olitems to it.

so when I run it and do the grouping I can really have more counts than I should because on olxpal has more than one olitem. It counts that more than  once.

I would do distinct but I have to keep my results the same for a later on UNION to copy to .dbf for a CrossTab format.

it has to have the :usxemp_, emname, cItemrech.iruser, cItemrech.irsrc, COUNT(cOoline.olxpal)

for the UNION since all the 7 other cursors have the same too.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
SET STEP ON 
select  usxemp_, emname, cItemrech.iruser, cItemrech.irsrc, COUNT(cOoline.olxpal) ;
from cItemrech, cOoline, cUserfile, cUserxtra, cprempm ;
where (irloc=lcLocTA or irloc=lcLocPM) AND irco=olico AND irloc=oliloc AND irord_=olord_ and irrel_=olrel_ and irsrc='W' AND irqty < 0 AND iritem=olitem AND ;
	  irloc=oliloc AND irky=olidky AND olfcrg!='Y' AND usid=iruser AND usxid=usid AND ememp_=usxemp_ and (emloc!=38 and emloc!=96 and emloc!=52) ;
group by iruser ;
order by iruser ;
into cursor cXEShip readwrite

Answer : Grouping by pallet#

Did you try changing

 COUNT(cOoline.olxpal)

to

 COUNT(DISTINCT cOoline.olxpal)

?
Random Solutions  
 
programming4us programming4us