Having a problem with a select query, hope you all can help me.
I this query:
To summarize: I'm adding up the JCDT_AMT wherever the job_type = 'B' and wherever the job_type = 'C' (Costs and billings.) I'm doing this for all job_nums where it matches the projectman in the UETD_PROJECTPER table. This way I can select a project manager and grab his jobs.
My problem came in when I found out that in the jcdetail table some of the jobs were sub jobs. In those cases, the jobnum would be different in the jcdetail table and the master job num that would actually exist in UETD_PROJECTPER table would be in a field in JCDETAIL called JOB_CTRL_NUM. The jobnum field in those cases would have a value of 'ALL' which doesn't exist in the UETD table. Consequently, I would end up missing records.
So how do I do the join for jcdetail.job_code against uetd_projectper.job_code when the jcdetail.job_code is a number and jcdetail.job_ctrl_code against uetd_projectper.job_code when jcdetail.job_code = 'ALL'?
A sproinging sound was heard....
I this query:
Code:
SELECT SUM(decode(JCDETAIL.JCDT_TYPE_CODE, 'C', JCDETAIL.JCDT_AMT, 0)) AS C_SUM, SUM(decode(JCDETAIL.JCDT_TYPE_CODE, 'B',
JCDETAIL.JCDT_AMT, 0)) AS B_SUM, UETD_PROJECTPER.PROJECTMAN
FROM JCJOBCAT FROM JCDETAIL, JCJOBCAT, JCJOBHPHS
WHERE
JCJOBCAT.JCAT_JOB_CODE = UETD_PROJECTPER.JOB_CODE AND
JCJOBCAT.JCAT_COMP_CODE = UETD_PROJECTPER.COMP_CODE AND
JCJOBCAT.JCAT_COMP_CODE = JCDETAIL.JCDT_COMP_CODE AND
JCJOBCAT.JCAT_JOB_CODE = JCDETAIL.JCDT_JOB_CODE AND
JCJOBCAT.JCAT_PHS_CODE = JCDETAIL.JCDT_PHS_CODE AND
JCJOBCAT.JCAT_CODE = JCDETAIL.JCDT_CAT_CODE
GROUP BY UETD_PROJECTPER.PROJECTMAN
To summarize: I'm adding up the JCDT_AMT wherever the job_type = 'B' and wherever the job_type = 'C' (Costs and billings.) I'm doing this for all job_nums where it matches the projectman in the UETD_PROJECTPER table. This way I can select a project manager and grab his jobs.
My problem came in when I found out that in the jcdetail table some of the jobs were sub jobs. In those cases, the jobnum would be different in the jcdetail table and the master job num that would actually exist in UETD_PROJECTPER table would be in a field in JCDETAIL called JOB_CTRL_NUM. The jobnum field in those cases would have a value of 'ALL' which doesn't exist in the UETD table. Consequently, I would end up missing records.
So how do I do the join for jcdetail.job_code against uetd_projectper.job_code when the jcdetail.job_code is a number and jcdetail.job_ctrl_code against uetd_projectper.job_code when jcdetail.job_code = 'ALL'?
A sproinging sound was heard....