Is it possible to optimize the code below? Would I be better of creating multiple cursors and joining the cursors?
Currently I'm just filling a grid with the result of this query. It takes about 13-15 seconds to execute, which really isn't long but would like to reduce this as much as possible. Appreciate any direction!
Currently I'm just filling a grid with the result of this query. It takes about 13-15 seconds to execute, which really isn't long but would like to reduce this as much as possible. Appreciate any direction!
Code:
SELECT T1.JOB, T1.LABOR, ROUND(T2.PURCHASES,2), T3.MAKE
FROM (SELECT JOB.JOB, SUM(LABOR.HOURS*LABOR.RATE) AS Labor FROM JOB LEFT OUTER JOIN LABOR ON JOB.JOB=LABOR.JOB WHERE JOB.STATUS <='4' GROUP BY JOB.JOB) T1
LEFT JOIN (SELECT JOB.JOB, SUM(COST.PRICE*COST.QTY) AS PURCHASES FROM JOB LEFT OUTER JOIN COST on JOB.JOB=COST.JOB WHERE JOB.STATUS<='4' GROUP BY JOB.JOB) T2
ON T1.JOB=T2.JOB
LEFT JOIN (SELECT JOB.JOB, SUM(REQ.QTY*PN.COST) as MAKE FROM ((JOB INNER JOIN WORDER ON JOB.JOB=WORDER.JOB) INNER JOIN REQ ON WORDER.WORDER=REQ.WORDER) INNER JOIN PN ON REQ.PN=PN.PN WHERE JOB.STATUS<='4' GROUP BY JOB.JOB) T3
ON T1.JOB=T3.JOB
INTO CURSOR TEST READWRITE