Solved

add a case statement to a selet nest statment

Posted on 2009-04-01
3
651 Views
Last Modified: 2013-12-18
hello
I have to  working statements that i want to combine  together. one is a case statement, the other is is a nest select statement.
Now i already have a left outer join in the select statement. when i go to add the workorder table to a new left outer join, so that i can add the case statment, i get and error.
please help :(

Thanks

case statement
 
SELECT ORGWON, 
CASE CLOSEDFLAG
WHEN 'Y' THEN 'CLOSED' 
WHEN 'N' THEN 'OPEN'
ELSE 'NA'
END AS WO_STATUS
FROM WORKORDER
 
 
select statement
 
SELECT T.ORGWON,NVL(B.TOTAL_PARTS,0)AS "TOTAL_PARTS",T.TOTAL_HOURS,(NVL(B.TOTAL_PARTS,0)+T.TOTAL_HOURS) AS "TOTAL_ALL"
 FROM
(
SELECT ORGWON, ROUND((TOTAL_HR)*(AVGCONTRATE),2) AS "TOTAL_HOURS"
FROM
(
select ORGWON,ROUND(SUM(reghours),2)AS "TOTAL_HR"
from logmaint.taskperson
where laborcde='01'
and employeetype='K'
GROUP BY ORGWON
)
, LOGMAINT.unitparameter
) T
LEFT OUTER JOIN
(
SELECT ORGWON,SUM(PARTS_TOTAL)AS "TOTAL_PARTS"
FROM (
SELECT TASKPERSON.ORGWON, QTYISSUE, ROUND((QTYISSUE)*(PRICE/MEASQ),2)AS "PARTS_TOTAL"
FROM LOGMAINT.WRKORDPART,LOGMAINT.CATALOG,LOGMAINT.TASKPERSON
WHERE CATALOG.NIINPNO=WRKORDPART.niinpno
AND TASKPERSON.ORGWON=WRKORDPART.ORGWON
AND QTYISSUE > '0'
and PARTINSTALLED='Y'
GROUP BY TASKPERSON.ORGWON,QTYISSUE,PRICE,MEASQ)
GROUP BY ORGWON
) B 
ON B.ORGWON= T.ORGWON

Open in new window

0
Comment
Question by:karephre
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
flow01 earned 500 total points
ID: 24041445
1 what error did you get
2  is the new join without the case clause (select CLOSEDFLAG itself) working
0
 
LVL 3

Author Comment

by:karephre
ID: 24041597
yes everything is work. I just Flow01 thanks for your quick response, but I just figured it out. I was trying to put all of my on operators all together at the end. It didnt t like that.
now my statement is good to go.
new query below
Thanks

SELECT T.ORGWON,NVL(B.TOTAL_PARTS,0)AS "TOTAL_PARTS",T.TOTAL_HOURS,(NVL(B.TOTAL_PARTS,0)+T.TOTAL_HOURS) AS "TOTAL_ALL",
CASE CLOSEDFLAG
WHEN 'Y' THEN 'CLOSED' 
WHEN 'N' THEN 'OPEN'
ELSE 'NA'
END AS WO_STATUS
 FROM
(
SELECT ORGWON, ROUND((TOTAL_HR)*(AVGCONTRATE),2) AS "TOTAL_HOURS"
FROM
(
select ORGWON,ROUND(SUM(reghours),2)AS "TOTAL_HR"
from logmaint.taskperson
where laborcde='01'
and employeetype='K'
GROUP BY ORGWON
)
, LOGMAINT.unitparameter
) T 
LEFT OUTER JOIN
WORKORDER WO
ON T.ORGWON=WO.ORGWON
LEFT OUTER JOIN
(
SELECT ORGWON,SUM(PARTS_TOTAL)AS "TOTAL_PARTS"
FROM (
SELECT TASKPERSON.ORGWON, QTYISSUE, ROUND((QTYISSUE)*(PRICE/MEASQ),2)AS "PARTS_TOTAL"
FROM LOGMAINT.WRKORDPART,LOGMAINT.CATALOG,LOGMAINT.TASKPERSON
WHERE CATALOG.NIINPNO=WRKORDPART.niinpno
AND TASKPERSON.ORGWON=WRKORDPART.ORGWON
AND QTYISSUE > '0'
and PARTINSTALLED='Y'
GROUP BY TASKPERSON.ORGWON,QTYISSUE,PRICE,MEASQ)
GROUP BY ORGWON
) B 
ON WO.ORGWON= B.ORGWON

Open in new window

0
 
LVL 3

Author Closing Comment

by:karephre
ID: 31565406
each on statement must be with its join.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question