Hello all,
Everyday I'm learning and getting better at SQL, with the help of some folks here at the forum I have made good improvements.
I just need some help, the code below works but takes a bit to get the data from 2 tables that are sitting on a server in a network. Can you please glance at my code and let me know if there's a better way to re-write this that can help to improve the time it takes to get the data?
These are my tables;
Table1 fields:
findcode, itemnum, skunum, descript, shipqty, ordqty, price, trannum, transferrable
Table2 fields:
pur_type, trannum, pur_date
Thank you
Everyday I'm learning and getting better at SQL, with the help of some folks here at the forum I have made good improvements.
I just need some help, the code below works but takes a bit to get the data from 2 tables that are sitting on a server in a network. Can you please glance at my code and let me know if there's a better way to re-write this that can help to improve the time it takes to get the data?
These are my tables;
Table1 fields:
findcode, itemnum, skunum, descript, shipqty, ordqty, price, trannum, transferrable
Table2 fields:
pur_type, trannum, pur_date
SQL:
SELECT table1.findcode, table1.itemnum, table1.skunum, table1.descript,;
SUM(IIF(pur_type=LOWER('i'), table1.shipqty*table1.price, 0.00)) as Price,;
SUM(IIF(pur_type=LOWER('i'), table1.ordqty, 0)) as Qty_ordered,;
SUM(IIF(pur_type=LOWER('i'), table1.shipqty, 0)) as Qty_Shipped,;
SUM(IIF(pur_type=LOWER('i'), table1.ordqty-table1.shipqty, 0)) as short_qty,;
SUM(IIF(pur_type=LOWER('i'), table1.price*(table1.ordqty-table1.shipqty), 0.00)) as Loss,;
SUM(IIF(pur_type=LOWER('c'), table1.shipqty, 0)) as cmQty,;
Sum(IIF(table2.pur_type=lower('c'), table1.shipqty*table1.price, 0.00)) as credit;
from z:\foxqp\table1.dbf;
inner JOIN z:\foxqp\table2.dbf;
ON table2.trannum = table1.trannum;
group BY table1.findcode, table1.itemnum, table1.descript, table1.skunum;
WHERE table2.pur_date >= DATE(2016,08,01) AND table2.pur_date <= DATE(2016,08,31);
AND table2.pur_type in('i','c') AND (table1.findcode is NOT null AND table.findcode <> ' ');
AND table1.transferrable = 'Y';
INTO CURSOR temp5
Thank you