Solved

add a case statement to a selet nest statment

Posted on 2009-04-01
3
646 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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 recover a database from a user managed backup

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now