Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

add a case statement to a selet nest statment

Posted on 2009-04-01
3
Medium Priority
?
657 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.‚Äč
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

604 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