Question : Data duplicates, triplicates....

So looking at the following SELECT what do you all see that I am not doing or doing wrong?

what I can tell is depending on how many lines there is on the order it will multiply that to how many times the items are displayed.

ie, order 123456 has 3 lines items on it I will see 3 * 3 = 9 records for really only 3.

I have gone through and made all that needs to be equal... Here's the code and the spread sheet of the results...
Is it the IIF()
sick and been a long week and I am stumped.
Thanks
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
**---- Display the layout
select iruser, ;
		SUM((IIF(irsrc='F' AND BLGRP!='35VNL' AND irqty<0,1,0)) +  (IIF(irsrc='P' AND BLGRP!='35VNL',1,0)) + ((IIF(irsrc='T' AND BLGRP!='35VNL' ;
			 AND irqty>0,1,0)) + (IIF(irsrc='G' AND BLGRP!='35VNL' AND irqty<0,1,0)) + ;	
			(IIF(irsrc='D' AND irqty<0 AND blgrp!='35VNL',1,0)) + (IIF(irsrc='W' AND irqty<0 AND blgrp!='35VNL',1,0)) + (IIF(irsrc='J' AND BLGRP!='35VNL' AND ;
			irqty<0,1,0)) + (IIF(irsrc='H' AND irqty<0 AND blgrp!='35VNL',1,0)))) as total_lines, ;
		sum(IIF(irsrc='F' AND BLGRP!='35VNL' AND irqty<0,1,0)) as cuts, ;
		SUM(IIF(irsrc='P' AND BLGRP!='35VNL' ,1,0)) as po_lines_recvd, ;
		sum(IIF(irsrc='T' AND BLGRP!='35VNL' AND irqty>0,1,0)) as xe_lines_recvd, ;
		SUM(IIF(irsrc='G' AND BLGRP!='35VNL' AND irqty<0,1,0)) as staged_lines, ;
		SUM(IIF(irsrc='D' AND BLGRP!='35VNL' AND irqty<0 AND ohviac!="1",1,0)) as shipped_lines, ;
		SUM(IIF(irsrc='D' AND BLGRP!='35VNL' AND irqty<0 AND ohviac="1" AND olloc=oliloc AND olord_=ohord_ and olrel_=ohrel_,1,0)) as willcall_lines, ;				
		SUM(IIF(irsrc='W' AND BLGRP!='35VNL' AND irqty<0,1,0)) as shipped_xe_lines, ;
		SUM(IIF(irsrc='J' AND BLGRP!='35VNL' AND irqty<0,1,0)) as consolidated_lines, ;
		SUM(IIF(irsrc='H' AND BLGRP!='35VNL' AND irqty<0,1,0)) as moved_lines ;
		from cItemrech, cBinloc, cUserfile, cUserxtra, cprempm, cOohead, cOoline ;
		where (irloc=41 OR irloc=57)  AND irbin=blbin AND irloc=blloc AND (usloc=41 OR usloc=57) AND usid=iruser AND usxid=usid AND ;
				ememp_=usxemp_  and (emloc!=38 AND emloc!=96) AND blgrp!='SAMPL' AND ohco=olco AND ohloc=olloc AND ohord_=olord_ and ohrel_=olrel_ and ;
				irooco=olco and iroolo=olloc and irord_=olord_ and irrel_=olrel_ and irooco=ohco AND iroolo=ohloc AND irord_=ohord_ and irrel_=ohrel_ and ;
				(oliloc=41 OR oliloc=57) AND olcust=ohcust AND ircust=olcust AND ircust=ohcust ;
		group by usxemp_ ;
		order by iruser into cursor cResultsIR readwrite
****************************************************************************************************************************************
*----------> Detail Code Next

SELECT cItemrech.irky, cOoline.olidky, cItemrech.irseq_, cOoline.olseq_, cItemrech.irloc, cItemrech.irsrc, cItemrech.iruser, cOohead.ohviac, cItemrech.irord_, cItemrech.irrel_, cItemrech.iritem, cItemrech.irqty, cItemrech.irbin ;
		 FROM cItemrech, cBinloc, cUserfile, cprempm, cUserxtra, cOoline, cOohead ;
		 where (irloc=41 or irloc=57) AND blgrp!='35VNL' AND BLGRP NOT LIKE 'XXXX%' AND irbin=blbin AND irloc=blloc AND ;
		 (usloc=41 OR usloc=57) AND  (emloc!=96 AND EMLOC!=38) AND usxid=usid AND ememp_=usxemp_ AND ;
		 usid=iruser AND irsrc in('F', 'P', 'T', 'G', 'D', 'W', 'J', 'H') AND ohco=olco AND ohloc=olloc AND ohord_=olord_ and ohrel_=olrel_ and ;
		 irooco=olco and iroolo=olloc and irord_=olord_ and irrel_=olrel_ and (oliloc=41 OR oliloc=57) AND olcust=ohcust AND ircust=olcust AND ircust=ohcust ;
		 order by irsrc, iruser into cursor cDetails readwrite
COPY TO "C:\pm_user\pacmat_user_details-"+Stuff(Stuff(Dtoc(ldDate),6,1,"_"),3,1,"_")+".xls" TYPE xl5

Answer : Data duplicates, triplicates....

It is impossible to help because we don't know your data and all their dependences. In addition to this you are not using aliases in your selects so it is impossible to imagine what means e.g. iroolo=olloc ...

The only known fact is: Your WHERE condition is not sufficient.

You have to start from one table:
SELECT *
FROM Table1 t1
and check if the number of records is correct.

Then add another table and join condition:
SELECT *
FROM Table1 t1, Table2 t2
WHERE t1.JoinColumn = t2.JoinColumn

If the number of records is still correct add the third table and its join condition:
SELECT *
FROM Table1 t1, Table2 t2, table3 t3
WHERE t1.JoinColumn = t2.JoinColumn
     AND t1.JoinColumn = t3.JoinColumn

If the number of records is not correct then you have to fix the join condition and then you may add the 4th table etc. If you need some filter condition to restrict number of records from certain table add it to the end of the WHERE:

SELECT *
FROM Table1 t1, Table2 t2, table3 t3
WHERE t1.JoinColumn = t2.JoinColumn
     AND t1.JoinColumn = t3.JoinColumn
     AND (t2.irloc=41 or t2.irloc=57)

If the fourth table needs two join conditions add them:
SELECT *
FROM Table1 t1, Table2 t2, table3 t3, Table4 t4
WHERE t1.JoinColumn = t2.JoinColumn
     AND t1.JoinColumn = t3.JoinColumn
     AND t3.JoinColumn1 = t4.JoinColumn1 AND t3.JoinColumn2 = t4.JoinColumn2
     AND (t2.irloc=41 or t2.irloc=57)

It is the first step of each SELECT command to know how data in tables are related and how to join them. When you have finished all the joins and filters then you may restrict the SELECT list:

SELECT t1.Col1, t1.Col2, t2.Col3, t4.Col5
FROM Table1 t1, Table2 t2, table3 t3, Table4 t4
WHERE t1.JoinColumn = t2.JoinColumn
     AND t1.JoinColumn = t3.JoinColumn
     AND t3.JoinColumn1 = t4.JoinColumn1 AND t3.JoinColumn2 = t4.JoinColumn2
     AND (t2.irloc=41 or t2.irloc=57)

Note the local aliases used everywhere.

If you need to calculate some sum or average do it in the next step and think about data groupping for these aggregate calculations. Before you start with calculations you have to be sure the number of records involved in is correct.

Remember the fact joining tables without appropriate conditons multiplies number of records on output.
SELECT *
  FROM Table1, Table2, Table3
will give you 27 records if each above table contains 3 records.

If you add just one join condition:
SELECT *
  FROM Table1 t1, Table2 t2, Table3 t3
  WHERE t1.JoinColumn = t2.JoinColumn
the result will still be 9 records...

As we don't know meaning of your tables and columns, and we don't know relations in your data, we cannot help to build join condition and the whole work is on you.

You could also be more patient and careful when formatting your SQL commands. The goal isn't the "command cube" but readable and structured command. You can easily understand such command when you come back to after several months:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
SELECT cItemrech.irky, cOoline.olidky, cItemrech.irseq_, cOoline.olseq_, ;
       cItemrech.irloc, cItemrech.irsrc, cItemrech.iruser, cOohead.ohviac, ;
       cItemrech.irord_, cItemrech.irrel_, cItemrech.iritem, cItemrech.irqty, cItemrech.irbin ;
  FROM cItemrech, cBinloc, cUserfile, cprempm, cUserxtra, cOoline, cOohead ; 
 WHERE irbin=blbin AND irloc=blloc AND ; 
       usxid=usid AND ememp_=usxemp_ AND ; 
       usid=iruser AND ohco=olco AND ;
       ohloc=olloc AND ohord_=olord_ AND ;
       ohrel_=olrel_ AND irooco=olco AND ;
       iroolo=olloc AND irord_=olord_ AND ;
       irrel_=olrel_AND olcust=ohcust AND ;
       ircust=olcust AND ircust=ohcust AND ; 
       (irloc=41 or irloc=57) AND blgrp!='35VNL' AND BLGRP NOT LIKE 'XXXX%' AND ;
       (usloc=41 OR usloc=57) AND  (emloc!=96 AND EMLOC!=38) AND 
       irsrc in('F', 'P', 'T', 'G', 'D', 'W', 'J', 'H') AND ;
       (oliloc=41 OR oliloc=57)
 ORDER BY irsrc, iruser 
  INTO CURSOR cDetails READWRITE
Random Solutions  
 
programming4us programming4us