tags:

views:

72

answers:

3

How can i use the END_DATE/START_DATE from the first sub select in the second subselect?, the provided values are only examples. (06/01/2010).

SELECT "PROJECT"."ID", 
        "PROJECT"."CLIENT", 
        "PROJECT"."NAME", 
        "PROJECT"."STATE", 
        "PROJECT"."EARLIEST_START", 
        "PROJECT"."LATEST_END", 
        "PROJECT"."EFFORT", 
        "PROJECT"."LINK", 
        "PROJECT"."STATUS", 
        "PROJECT"."DESCRIPTION", 
        (SELECT SUM((END_DATE - START_DATE + 1) * (WORKLOAD / 100)) 
           FROM WORKITEM WHERE PROJECT = PROJECT.ID
        ) AS "P_A", 
        (SELECT COUNT(*) 
          FROM PUBLIC_HOLIDAY 
          WHERE HOLIDAY_DATE BETWEEN TO_DATE('06/1/2010','MM/DD/YYYY') AND 
                                   TO_DATE('06/2/2010','MM/DD/YYYY')) AS P_B,
        "PROJECT_STATE"."STATE", 
        "PERSON"."DISPLAY_NAME" AS "RESPONSIBLE" 
        FROM "PROJECT"
        INNER JOIN "PROJECT_STATE" ON PROJECT.STATE = PROJECT_STATE.ID
        INNER JOIN "PERSON" ON RESPONSIBLE = PERSON.ID
        WHERE (PROJECT.CLIENT = '1') AND (PROJECT.STATE = 1)
        ORDER BY "PROJECT"."NAME" ASC
A: 

You cannot. You could make a single subselect from the two using a join, and move the new composite subselect from the SELECT part to the FROM part of the main query.

kicsit
A: 

Is this what you are looking for

    SELECT "PROJECT"."ID", 
        "PROJECT"."CLIENT", 
        "PROJECT"."NAME", 
        "PROJECT"."STATE", 
        "PROJECT"."EARLIEST_START", 
        "PROJECT"."LATEST_END", 
        "PROJECT"."EFFORT", 
        "PROJECT"."LINK", 
        "PROJECT"."STATUS", 
        "PROJECT"."DESCRIPTION", 
        (SELECT SUM((END_DATE - START_DATE + 1) * (WORKLOAD / 100)) 
           FROM WORKITEM WHERE PROJECT = PROJECT.ID
        ) AS "P_A", 
        (SELECT COUNT(*) 
          FROM PUBLIC_HOLIDAY 
          WHERE HOLIDAY_DATE BETWEEN NVL(END_DATE,SYSDATE) AND 
                                   NVL(START_DATE,SYSDATE)) AS P_B,
        "PROJECT_STATE"."STATE", 
        "PERSON"."DISPLAY_NAME" AS "RESPONSIBLE" 
        FROM "PROJECT"
        INNER JOIN "PROJECT_STATE" ON PROJECT.STATE = PROJECT_STATE.ID
        INNER JOIN "PERSON" ON RESPONSIBLE = PERSON.ID
        LEFT JOIN "WORKITEM" ON WORKITEM.PROJECT = WORKITEM.ID 
        WHERE (PROJECT.CLIENT = '1') AND (PROJECT.STATE = 1)
        ORDER BY "PROJECT"."NAME" ASC
Bharat
A: 

Here is one way to use start_date and end_date in more than one place

with (select to_date('06/01/2010','MM/DD/YYYY') as start_date,  
             to_date('06/02/2010','MM/DD/YYYY') as end_date  
        from dual) as q1  
select project.id,
       project_state.state, 
       q1.start_date,
       q1.end_date,
       (SELECT SUM((q1.END_DATE - q1.START_DATE + 1) * (WORKLOAD / 100)) 
       FROM WORKITEM WHERE PROJECT = PROJECT.ID) AS P_A 
 from project  
 join project_state on project_state.id = project.state 
 join q1 on 1=1  
coop