Solved

add a case statement to a selet nest statment

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
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 …
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

930 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

10 Experts available now in Live!

Get 1:1 Help Now