Solved

add a case statement to a selet nest statment

Posted on 2009-04-01
3
654 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
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.

728 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