Outer join problem (ORA-01799)

We have a database design roughly as follows:
- A STAFF table (columns don't matter here).
- Resources have a cost per hour that varies over time, so we have a STAFF_COST table with an effective date and a cost per hour
- A PROJECT table (columns don't matter here).
- Projects can have staff assigned, so we have a PROJECT_STAFF table which has foreign keys to the PROJECT and STAFF table.
- Project staff have a cost per hour, which can vary over time, and be different to the (default) staff costs. So we have a PROJECT_STAFF_COST table which uses the PROJECT_STAFF foreign key, with an effective date and a cost per hour
- Staff work on tasks so we have a TIMESHEET_TASK and TIMESHEET_DAY tables which define a project worked on, task within the project (optional as time can be 'entered against the project', who is recording the time, the hours worked and the day the hours were worked.
So when timesheet information is entered we have three scenario's that we need to cover.
1) The resource is a member of the project and the hours were worked on a day for which we have a project staff cost. That is, the project staff cost table has one or more rows for the staff member assigned to the given project with an effective date before the date the hours were entered against.
2) The resource is a member of the project but the hours were worked on a day for which we do not have a project staff cost. That is, the project staff cost table has one or more entries for the staff member assigned to the given project, but all the effective dates are after the date the hours were entered against.
3) The resource is not a member of the project. That is, the project staff cost table does not have any rows for the staff member. Time was entered 'against the project'.
We need to work out the actual cost of the project. So we need to retrieve every day's timesheet entry, returning the hours assigned and the cost per hour relevant for that day. I have the following query:
select tsh.staff_id, s.full_name, tsd.entry_date, tsd.hours as ProjectHours,
psCOST_INFO.cost_per_hour as ProjectCost
from timesheet_day tsd
inner join timesheet_task tst on tst.timesheet_task_id = tsd.timesheet_task_id
inner join timesheet_header tsh on tst.timesheet_header_id = tsh.timesheet_header_id
inner join staff s on s.staff_id = tsh.staff_id
left join (Select ps.project_id, ps.staff_id, psc.project_staff_id, psc.effective_date, psc.cost_per_hour
from project_staff ps
inner join project_staff_cost psc on ps.project_staff_id = psc.project_staff_id) as psCOST_INFO
on psCOST_INFO.staff_id = tsh.staff_id and psCOST_INFO.project_id = tst.project_id
and psCOST_INFO.effective_date = (select max(ps2.effective_date) from project_staff_cost ps2
where ps2.project_staff_id = psCOST_INFO.project_staff_id
and ps2.effective_date <= tsd.entry_date)
where tst.project_id = 55825
Using the left join covers scenario's 2 and 3 above because I will get null in the cost columns and can then take appropriate action. If I were to use an inner join, then hours in timesheets from scenario's 2 and 3 would be excluded, which is not what we want.
The subselect using the MAX aggregate function is required to get the cost per hour most relevant for the timesheet day. That is, if there are several effective dates for the project staff member before the date in question, we want the most recent one. We can't just use the MAX one, however in case there is an effective date after the particular timesheet date. Sheesh...
This query works fine in SQL Server. It it not allowed in Oracle and returns an ORA-01799 column may not be outer joined to a subquery.
I'm not going to bother to ask why not. I just need a way to do what I want. I've spent days trying to move the code around but I either end up with an inner join (which returns fewer rows than I want) or it just plain don't work.
Can someone help me rework this query to achieve the result I want?
Thanks, Andrew

Thanks for your reply, Laurent. In my experience trying to cut important corners in explaining a problem only serves to make it more difficult to solve. That pretty much was the smallest reproducable query that demonstrates the complexity of the problem I have. I'm not just trying to get which publishers live in the 'CA' state here...
From what I have just read about rank() it serves the same purpose as max() on a given column, and getting the maximum or top ranked one just doesn't cut it. As I said in my original post that provided all the relevant (and no spurious) information on the problem, it is possible that there are effective dates AFTER the date we are interested in and they have to be excluded.
I have to get the project staff cost row with the latest date that is before the timesheet date. That means I have to reference data in the outer query. Oracle seems to have a problem with that when used in an outer join.
We are currently going down the track of 3 UNION'd statement to cover the 3 scenario's. A single query would be more efficient so if anyone can provide guidance I would appreciate it.
Thanks, Andrew

Similar Messages

  • Outer Join problems - "ORA-30563 outer join operator (+) not allowed in select-list"

    Products: Discoverer 4.1.33.0.2
    (Admin and User/Plus)
    8i EE 8.1.7 (Discoverer server)
    8i EE 8.1.5 ('source data' server)
    Background assumptions: (1) If a column from an "outer-joined" table is compared to a constant, the outer join operator must be applied to that column in order for the outer join to work. (2) A 'Condition' specified in Discoverer User/Plus manifests as a comparison to a constant.
    I created a join in Admin between two folders, selected 'outer join on detail' option. In User/Plus, created worksheet containing columns from the joined folders. When no Conditions are NOT specified, results seem ok. However, when Condition IS added, worksheet encounters "ORA-30563 outer join operator (+) not allowed in select-list" and returns blank sheet.
    To workaround, created Custom folder with outer join in place. Didn't work either with Conditions specified. No error, but I think that because Discoverer did not 'outer join' the Condition column, the outer join was ignored.
    Any insights, ideas, or workarounds are much appreciated.
    -Jim

    If you build a query that uses an outer join then any items from the potentially deficient side of the join will have (+) appended to them everywhere in the sql. Up until 8.1.7 this was OK in the select list as it was just treated as noise and ignored - However this now fails with ORA-30563:
    outer join operator (+) not allowed in select-list...
    In 4.1.33.1.6 you get the error 'ORA-30563 outer join operator(+) not allowed in select list'.
    In 4.1.36.1.10 the query runs OK.. Your work around I would guess would be to create a custom folder as you suggested.

  • OUTER JOIN -- Error: ORA-01417  (a table may be outer joined to at most one

    Hi there,
    I have a rather simple task: retrieve all the records in a table, for agiven domain p_domain_id (input parameter). The problem is that there are about 6 FKs in the table, and I need the names (strings) corresponding to those FKs (from other tables). Unfortunately, some of the FKs are NULL, so in '=' I loose records. Without the last 2 lines in WHERE clause, I get the correct result. With d2 in place (and without the "(+)" ) I loose 2 records. With the d3 (and also without "(+)"), I do not get any record.
    With the "(+)", the code compiles but I get the run time error ORA-01417
    NOTE: I put the "+" within parentheses, in order to show it like a text in this editor.
    What's an elegant solution to this?
    Thanks a lot.
    Here's the code:
    SELECT
    a.DOMAIN,
    b.NAME,
    a.DE_ID,
    a.NAME,
    a.PREFERRED_LABEL,
    a.TECHNICAL_DEFINITION,
    a.PUBLIC_DEFINITION,
    a.DE_TYPE,
    c1.NAME,
    a.HAS_PARAMETER,
    a.VALUE_CLASS,
    c2.NAME,
    a.INDEX_TERMS,
    a.DATA_TABLE_ID,
    d1.TABLE_NAME,
    a.SP_INSERT,
    a.SP_UPDATE,
    a.SP_GET_BYMRN,
    a.SP_GET_BYATTRIBUTE,
    a.VALUE_TABLE_ID,
    d2.TABLE_NAME,
    a.PARAM_TABLE_ID,
    d3.TABLE_NAME,
    a.PARAM_DOMAIN_LOGIC,
    a.SP_LOV,
    a.LOWER_LIMIT,
    a.UPPER_LIMIT,
    a.BOOLEAN_Y,
    a.BOOLEAN_N,
    a.COMMENTS,
    a.ENTERED_BY,
    commons_API.get_person_full_name(a.ENTERED_BY),
    a.ENTERED_ON
    FROM
    DATA_ELEMENT_INDEX a,
    DE_DOMAIN b,
    GENERAL_LIST c1,
    GENERAL_LIST c2,
    TABLE_GROUP d1,
    TABLE_GROUP d2,
    TABLE_GROUP d3
    WHERE
    DOMAIN = p_domain_id AND
    b.DOMAIN_ID = a.DOMAIN AND
    c1.ID = a.DE_TYPE AND
    c2.ID = a.VALUE_CLASS AND
    d1.TABLE_ID = a.DATA_TABLE_ID AND -- it works well without the next two lines
    d2.TABLE_ID = a.VALUE_TABLE_ID "(+)" AND
    d3.TABLE_ID = a.PARAM_TABLE_ID "(+)"
    ORDER BY a.NAME;
    Edited by: user10817976 on Oct 19, 2009 8:14 AM

    One of my standard replies...
    Oracle syntax does not support outer joining to more than one table.
    However ANSI syntax does...
    SQL> select * from a;
            ID      B_KEY      C_KEY
             1          2          3
             2          1          4
             3          3          1
             4          4          2
    SQL> select * from b;
            ID     C_KEY2
             1          1
             2          5
             3          3
             4          2
    SQL> select * from c;
          KEY1       KEY2 DTA
             1          1 1-1
             1          2 1-2
             1          3 1-3
             1          4 1-4
             2          1 2-1
             2          2 2-2
             2          3 2-3
             2          4 2-4
             3          1 3-1
             3          2 3-2
             3          3 3-3
             3          4 3-4
             4          1 4-1
             4          2 4-2
             4          3 4-3
             4          4 4-4
    16 rows selected.
    SQL> ed
    Wrote file afiedt.buf
      1  select a.id as a_id, b.id as b_id, c.key1 as c_key1, c.key2 as c_key3, c.dta
      2  from a, b, c
      3  where a.b_key = b.id
      4  and   a.c_key = c.key1 (+)
      5* and   b.c_key2 = c.key2 (+)
    SQL> /
    and   a.c_key = c.key1 (+)
    ERROR at line 4:
    ORA-01417: a table may be outer joined to at most one other table
    SQL> ed
    Wrote file afiedt.buf
      1  select a.id as a_id, b.id as b_id, c.key1 as c_key1, c.key2 as c_key3, c.dta
      2  from a JOIN b ON (a.b_key = b.id)
      3*        LEFT OUTER JOIN c ON (a.c_key = c.key1 and b.c_key2 = c.key2)
    SQL> /
          A_ID       B_ID     C_KEY1     C_KEY3 DTA
             3          3          1          3 1-3
             4          4          2          2 2-2
             2          1          4          1 4-1
             1          2
    SQL>

  • Left outer join problem -- need feedback

    using crystal 2008
    haveing prolbems with a left outerjoin to get a blank field(null) to show up.
    basically i have some po line have have long descriptions or text fields that i want to include with the report. Below is my sql statement. I have written a formula with a join between 2 fields to get the report to work- this does but- it leave the polines off that do not have a long description.  I have tried left outer joins but seem to be having problems.  The long description field where the data is actually at is under my po.line table, although serveral area have long description fields -
    *one note i had to add a duplicate table to the field to get some items in my header to work properly - not sure if this is effecting the report or not.
    OK- when I set up the link to a LO join enforce from = to
    and dont add the ldtext.field to the report the left outjoin works(but no long description)and all my line items show up.
    1. when I keep the same join and add either just the ld.text field to  the report it comes back with a error saying invalid table
    2. when i use my formula that joins the ld.text and po.line and place it in the report with the same left outerjoin i get the same failure.
    3.  when i dont reference the ldtext(field) at all in the report it works fine w/ the lo join
    4. when i Dont use a left outer join and use my formula(see below)
    if not isnull(({LONGDESCRIPTION.LDTEXT }))
    then {POLINE.DESCRIPTION}+{LONGDESCRIPTION.LDTEXT}
    else {POLINE.DESCRIPTION}
    and link from poline.ld
    to ld.ldtext - my formula works and populates the po.line and the ld.text together - except that any po.line with no description will not show up. Like its not there.
    Not sure what to do?
    here is my current sql statement with the longdescription field in the select statement
    here is the error statement i am getting:
    Failed to retrieve data from the database:
    Details:42000[intersolv][odb sql base driver][sql base] 00906 itn invalid table name[database vendor code:906]
    sql statement:
    SELECT "PO"."PONUM", "PO"."STATUS", "PO"."VENDOR",
    "COMPANIES"."NAME", "COMPANIES"."ADDRESS1",
    "COMPANIES"."ADDRESS2", "COMPANIES"."ADDRESS3",
    "COMPANIES"."ADDRESS4", "COMPANIES"."PHONE",
    "COMPANIES"."FAX", "COMPANIES_1"."NAME",
    "COMPANIES_1"."ADDRESS1", "COMPANIES_1"."ADDRESS2",
    "COMPANIES_1"."ADDRESS3", "COMPANIES_1"."ADDRESS4",
    "COMPANIES_1"."CONTACT", "COMPANIES_1"."PHONE",
    "COMPANIES_1"."FAX", "PO"."PURCHASEAGENT",
    "PO"."ORDERDATE",
    "PO"."REQUIREDDATE", "PO"."PAYMENTTERMS",
    "PO"."SHIPVIA", "PO"."FREIGHTTERMS", "PO"."FOB",
    "POLINE"."DESCRIPTION", "POLINE"."ITEMNUM",
    "POLINE"."ORDERQTY", "POLINE"."UNITCOST",
    "POLINE"."LOADEDCOST", "POLINE"."POLINENUM",
    "PO"."SHIPTOATTN", "LONGDESCRIPTION"."LDTEXT"
    FROM   ("MAXIMO"."PO" "PO" LEFT OUTER JOIN
    "MAXIMO"."LONGDESCRIPTION" "LONGDESCRIPTION" ON "PO"."LDKEY"="LONGDESCRIPTION"."LDKEY"),
    "MAXIMO"."POLINE" "POLINE",
    "MAXIMO"."COMPANIES" "COMPANIES_1",
    "MAXIMO"."COMPANIES" "COMPANIES"
    WHERE  ("PO"."PONUM"="POLINE"."PONUM") AND ("PO"."VENDOR"="COMPANIES_1"."COMPANY") AND ("PO"."SHIPTO"="COMPANIES"."COMPANY") AND "PO"."PONUM"='3386-053'

    If you took the time to read this thanks.... turns out... and I just want to pull my hair out over this.  My connection had a  old odbc driver so somehow it would not allow a left outer join....go figure - weeks of agony over that..... thanks ....have to say love this forum.

  • Correlated sub-query/outer join problem

    Hi,
    I have a problem similar to this one (Outer join with correlated subquery but I'm struggling to find a solution for mine!
    The following query works OK unless there is no entry in room_prices, so I need to outer join somehow to that table otherwise it doesn't return any rows.
    The main difference between the query in the other thread and mine is that mine has an extra table (bookings b) in the sub-query, which is complicating things a bit.
    select b.book_from,
         b.book_to,
         b.flat_rate,
         nvl(c.discount,0),
         p.hourly,
         p.half_day,
         p.daily,
         p.discountable,
         p.surcharge,
         l.evening_start,
         nvl(b.full_day,'N')
    from booking.bookings b,
    booking.customer c,
    booking.room_prices p,
    booking.rooms r,
    booking.location l
    where b.id = 9272
    and c.id = b.customer
    and b.room = p.room
    and b.room = r.id
    and r.loc = l.id
    and p.from_date =
    select max(p2.from_date)
    from booking.room_prices p2
    where p2.room = p.room
    and p2.from_date < b.book_from
    Could anyone suggest a way to re-write the query so that it is outer joined to room_prices?
    Thanks,
    Hazel

    Thanks for both of your responses.
    Unfortunately your suggestion didn't work Dmytro - still no rows are returned.
    Here are some table creation scripts and test data to insert:
    CREATE TABLE BOOKINGS
    ID NUMBER NOT NULL,
    ROOM NUMBER NOT NULL,
    CUSTOMER NUMBER NOT NULL,
    BOOK_FROM DATE NOT NULL,
    BOOK_TO DATE NOT NULL,
    CONFIG VARCHAR2(24) NOT NULL,
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    DELEGATES NUMBER,
    NARRATIVE VARCHAR2(256),
    CONTACT_DETAILS VARCHAR2(400),
    CONFIRMED VARCHAR2(1),
    CANC_REASON NUMBER,
    FULL_DAY VARCHAR2(1),
    FLAT_RATE NUMBER,
    STANDBY NUMBER,
    TOTAL_STANDBY_TIME DATE,
    PRE_STANDBY_TIME DATE,
    PRE_STANDBY NUMBER,
    GL_CODE VARCHAR2(20)
    CREATE TABLE CUSTOMER
    ID NUMBER NOT NULL,
    CUSTOMER VARCHAR2(160) NOT NULL,
    CONTACT_ADDRESS VARCHAR2(240),
    CONTACT_TELEPHONE VARCHAR2(20),
    CONTACT_EMAIL VARCHAR2(160),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    DISCOUNT NUMBER(5,2),
    CUST_TYPE VARCHAR2(1),
    CONTACT_FAX VARCHAR2(20),
    DEBTOR_NO VARCHAR2(20),
    BC_CONTACT VARCHAR2(64)
    CREATE TABLE ROOMS
    ID NUMBER NOT NULL,
    LOC NUMBER NOT NULL,
    NAME VARCHAR2(160) NOT NULL,
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    ACTIVE VARCHAR2(1),
    ROOM_DESC VARCHAR2(2000)
    CREATE TABLE LOCATION
    ID NUMBER NOT NULL,
    NAME VARCHAR2(240) NOT NULL,
    ADDRESS VARCHAR2(240),
    PCODE VARCHAR2(8),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    CONF_RDF VARCHAR2(10),
    CLOSING VARCHAR2(5),
    EVENING_START VARCHAR2(5)
    CREATE TABLE ROOM_PRICES
    ROOM NUMBER NOT NULL,
    FROM_DATE DATE NOT NULL,
    HOURLY NUMBER(6,2),
    HALF_DAY NUMBER(6,2),
    DAILY NUMBER(6,2),
    DISCOUNTABLE VARCHAR2(1),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    SURCHARGE NUMBER(6,2)
    Insert into bookings
    (ID, ROOM, CUSTOMER, BOOK_FROM, BOOK_TO, CONFIG, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, DELEGATES, NARRATIVE, CONTACT_DETAILS, CONFIRMED, FLAT_RATE, PRE_STANDBY_TIME, PRE_STANDBY)
    Values
    (9272, 7466, 4946, TO_DATE('10/25/2005 10:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/25/2005 13:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Default', TO_DATE('10/27/2005 15:35:02', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', TO_DATE('10/27/2005 15:36:26', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 1, 'another meeting', 'Hazel', 'Y', 40, TO_DATE('10/25/2005 09:30:00', 'MM/DD/YYYY HH24:MI:SS'), 1800);
    Insert into customer
    (ID, CUSTOMER, CONTACT_ADDRESS, CONTACT_TELEPHONE, CREATED_DATE, CREATED_BY, CUST_TYPE, BC_CONTACT)
    Values
    (4946, 'Association of Teachers', 'Address', '0191 8887777', TO_DATE('09/22/2003 08:05:47', 'MM/DD/YYYY HH24:MI:SS'), 'Dataload', 'B', 'Miss Jones');
    Insert into rooms
    (ID, LOC, NAME, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, ACTIVE)
    Values
    (7466, 308, ' Counselling Room 1', TO_DATE('04/11/2005 10:55:33', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/22/2005 14:43:50', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 'Y');
    Insert into location
    (ID, NAME, ADDRESS, PCODE, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, CONF_RDF, CLOSING, EVENING_START)
    Values
    (308, 'Business Centre', 'Address', 'NE30 1NT', TO_DATE('03/19/2003 13:07:35', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/09/2005 11:17:09', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', 'BKCF_2', '22:30', '18:00');
    Thanks,
    Hazel

  • Query Outer Join Problem

    I need to join these two tables and have a problem becuase it's difficult to join the tables with the keys.
    Basically here is a sample of the data.
    The only way I get the correct number of rows returned is with a left outer join on unit, asset_id and sequence_number.
    COST
    unit asset_id sequence_number
    01 113317 0
    01 113317 1
    01 113317 1
    ACQ_DETAIL
    unit asset_idnbsp sequence_number vendor_id
    01 113317 1 ABCConstruction
    So with the left outer join you'd get
    unit asset_idnbsp sequence_number vendor_id
    01 113317 0
    01 113317 1 ABCConstruction
    01 113317 1 ABCConstruction
    I need to join on sequence_number or else I get too many rows returned. Is there anyway I can keep the outer join (still joining on thows three keys) and have this returned.
    unit asset_idnbsp sequence_number vendor_id
    01 113317 0 ABCConstruction
    01 113317 1 ABCConstruction
    01 113317 1 ABCConstruction
    Thanks all!!

    COST
    unit         asset_id           seq_no   
    [pre]01            1137                   0        
    [pre]01            1137                   1        
    [pre]01            1137                   1       
    ACQ_DET
    [pre]unit         asset_id           seq_no      vendor_id  
    [pre]01            1137                   1              ABC      
    [pre]01            1137                   3              XYZ       
    RETURNS
    [pre]01            1137                   ABC           
    [pre]01            1137                   ABC           
    [pre]01            1137                   ABC           
    THANKS!!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Left Outer Join Problem for Multiple Condition

    Hi This is the code and I want to return the vlaues evens if it is not ther so my Sysntax is not right for that can you plz help me
    SELECT ap.descripcion AS Production_Description,
    conceptes.descripcion AS Concepts_Description ,
    um.Nomenclatura AS Unit_Measure ,
    -- real_daily_detail.FechaProduccion AS Production_Date ,
    period.Codigo as June,
    period.anio AS YEAR_08 ,
    rmd.Valor AS Values_Monthly,
    budgetd.Valor as Budget
    FROM sgr_area_produccion ap ,
    sgr_conceptos conceptes ,
    SGR_Unidad_Medida um ,
    SGR_Unidad_Produccion up ,
    SGR_Unidad_Area_Produccion uap ,
    SGR_Real_Mensual_Detalle rmd ,
    SGR_Periodo period ,
    SGR_Real_Mensual rm ,
    SGR_Presupuesto budget ,
    SGR_Presupuesto_Detalle budgetd
    where uap.ID_Unidad_Produccion = up.ID_Unidad_Produccion (+)
    and uap.ID_Area_Produccion = ap.ID_Area_Produccion (+)
    and rm.ID_Area_Produccion = uap.ID_Area_Produccion (+)
    and rm.ID_Unidad_Produccion = uap.ID_Unidad_Produccion (+)
    and rmd.ID_Unidad_Produccion = rm.ID_Unidad_Produccion (+)
    and rmd.ID_Area_Produccion = rm.ID_Area_Produccion (+)
    and rmd.ID_Periodo = rm.ID_Periodo (+)
    and period.ID_Periodo = rm.ID_Periodo (+)
    and conceptes.ID_Concepto = rmd.ID_Concepto (+)
    and budget.ID_Unidad_Produccion = uap.ID_Unidad_Produccion(+)
    and budget.ID_Area_Produccion = uap.ID_Area_Produccion (+)
    and budget.ID_Unidad_Produccion = budgetd.ID_Unidad_Produccion
    and budget.ID_Area_Produccion = budgetd.ID_Area_Produccion (+)
    and budget.ID_Periodo = budgetd.ID_Periodo (+)
    and period.ID_Periodo = budget.ID_Periodo (+)
    and period.Codigo = 'JUNIO-08'
    and conceptes.ID_Concepto = budgetd.ID_Concepto (+)
    and daily.ID_Area_Produccion = uap.ID_Area_Produccion (+)
    and daily.ID_Unidad_Produccion = uap.ID_Unidad_Produccion (+)
    and dailyd.ID_Unidad_Produccion = daily.ID_Unidad_Produccion(+)
    and dailyd.ID_Area_Produccion = daily.ID_Area_Produccion (+)
    and period.ID_Periodo = daily.ID_Periodo (+)
    and conceptes.ID_Concepto = dailyd.ID_Concepto (+)
    and um.ID_Unidad_Medida = conceptes .ID_Unidad_Medida (+)

    Oracle old outer join syntax had more restrictions than more recent ANSI outer join syntax. I do'nt want to emulate compiler and go through your code to spot any possible problems, even more if you cannot say also the exact error or exact problem what you get.
    And bear in mind that for outer joins THERE IS DIFFERENCE [url http://www.gplivna.eu/papers/sql_join_types.htm#p6.4]between join conditions and predicates in where clause.
    Gints Plivna
    http://www.gplivna.eu

  • Using FILTER after a FULL OUTER JOIN problem in OWB

    Hi,
    I’m using OWB 11.2.
    In an OWB mapping I need to detect every changes (Insert, Update, Delete) made to the data of a table. In order to find these changes I need to use “FULL OUTER JOIN” and a “FILTER” to join current table to previous table.
    My desired generated query should be like this:
    Select *
    From tab1 FULL OUTER JOIN tab2 on JOIN_CONDITION
    WHERE FILTER_CONDITION
    The problem is that when OWB generates the code, the query will be like this:
    Select *
    From tab1 FULL OUTER JOIN tab2 on JOIN_CONDITION AND FILTER_CONDITION
    As you know these 2 queries are not the same at all!
    I don’t know how to make OWB generate my desired SQL. Please help me…

    Works ok on 11.2.0.3
    Are you using "( + )" for join condition in joiner? Or, are you using "Join input role" parameter to define full outer join condition? Are you using oracle or ANSI syntax?

  • Outer join problem?

    I'm trying to make a query that compares the hours, filled in by an employee in OTL (oracle time and labour) for a certain projectnumber, with the actually transferred hours to this projectnumber in oracle projects.
    The expenditure date on the otl side has one value. The same date on the projects side has 3 values. I would like to have the non corresponding values on the otl side filled with the value "null". As it is now they are all filled with the one value it has found (for instance 8 hours). It has probably to do with an outer join but i just can not get it right.
    The query has become rather complicated. See below.
    I hope you guys can help me out.
      SELECT distinct
    ppa.segment1                          
      ,papf.full_name                       
      ,papf.employee_number
      ,pt.task_number                             
      ,hta.attribute3                         
      ,to_char(htb0.start_time,'ww')
      ,htb1.start_time                  "Expenditure Date "
      ,htb.measure                      "Hours OTL"   
      ,peia.QUANTITY  "Hours projects"
      ,(htb.measure-peia.QUANTITY)
      ,to_char(htb0.start_time,'YYYY') FROM
    pa.pa_projects_all ppa
    ,pa.pa_tasks pt
    ,pa.pa_project_types_all ppta
    ,hr.hr_all_organization_units haou
    ,hr.hr_all_organization_units haou1
    ,hxc.hxc_time_building_blocks htb
    ,hxc.hxc_time_attributes hta
    ,hxc.hxc_time_attribute_usages htau
    ,hr.per_all_assignments_f paaf
    ,hr.per_all_people_f papf
    ,hr.per_all_people_f papfsup
    ,hr.per_all_people_f papfcreat
    ,hxc.hxc_time_building_blocks htb0
    ,hxc.hxc_time_building_blocks htb1
    ,hxc.hxc_timecard_summary hts
    ,applsys.fnd_user fu
    ,apps.PA_EXPEND_ITEMS_ADJUST2_V peia
    WHERE
    ppa.CARRYING_OUT_ORGANIZATION_ID = haou.organization_id
    and paaf.person_id = papf.person_id
    and htb1.start_time BETWEEN paaf.effective_start_date and paaf.effective_end_date
    and haou1.organization_id = paaf.organization_id
    and htb.time_building_block_id = htau.time_building_block_id
    and htb.object_version_number= htau.time_building_block_ovn
    and htau.time_attribute_id = hta.time_attribute_id
    and htb.date_to = apps.hr_general.end_of_time
    and htb.SCOPE = 'DETAIL'
    and htb.resource_id = papf.person_id
    and htb1.start_time BETWEEN papf.effective_start_date and papf.effective_end_date
    and hta.ATTRIBUTE_CATEGORY = 'PROJECTS'
    and ppa.project_id = hta.attribute1
    and pt.task_id = hta.attribute2
    and ppta.project_type = ppa.project_type
    and htb1.parent_building_block_id = htb0.time_building_block_id
    and htb0.SCOPE = 'TIMECARD'
    and htb0.resource_id = papf.person_id
    and htb.PARENT_BUILDING_BLOCK_ID = htb1.TIME_BUILDING_BLOCK_ID
    and htb.resource_id = htb1.resource_id
    and htb0.time_building_block_id = hts.timecard_id
    and htb0.resource_id = hts.resource_id
    and htb1.SCOPE = 'DAY'
    and htb1.resource_type = 'PERSON'
    and HTB1.OBJECT_VERSION_NUMBER =
      (SELECT MAX(htb4.OBJECT_VERSION_NUMBER)  
    FROM   hxc.hxc_time_building_blocks htb4  
    WHERE  htb4.resource_id = htb1.resource_id
    and    htb1.PARENT_BUILDING_BLOCK_ID= htb4.PARENT_BUILDING_BLOCK_ID)
    and htb0.resource_type = 'PERSON' and htb0.object_version_number =
      (SELECT MAX(htb4.object_version_number)  
    FROM hxc.hxc_time_building_blocks htb4  
    wHERE htb4.resource_id = htb0.resource_id  
    and htb0.time_building_block_id  = htb4.parent_building_block_id)    
    and paaf.SUPERVISOR_ID                        = papfsup.PERSON_ID (+)
    and htb.CREATED_BY                            = fu.USER_ID
    and fu.EMPLOYEE_ID                            = papfcreat.PERSON_ID
    and papf.PERSON_ID                            = papfcreat.PERSON_ID
    and to_char(htb0.start_time,'YYYY')           = nvl(&jaar,to_char(htb0.start_time,'YYYY')) 
    and to_char(htb0.start_time,'ww')             = nvl(&week_num,to_char(htb0.start_time,'ww')) 
    and papf.employee_number                      = nvl(&ambt_num,papf.employee_number)  -- medewerker nummer
    and peia.PROJECT_ID                           =  ppa.PROJECT_ID  
    and peia.TASK_ID                              =   pt.task_id 
    and peia.PROJECT_TYPE                         =  ppa.project_type                                                  
    and peia.INCURRED_BY_PERSON_ID                = fu.EMPLOYEE_ID
    and peia.CC_RECVR_ORGANIZATION_ID             = haou.organization_id 
    and peia.EXPENDITURE_ITEM_DATE                = htb1.start_time
    and nvl(upper(papfsup.FULL_NAME),'GEEN SUP')           like nvl(upper('%&supervisor%'),nvl(upper(papfsup.FULL_NAME),'Geen sup'))
    and upper(papf.FULL_NAME)                              like nvl(upper('%&naam%'),upper(papf.FULL_NAME)) -- medewerker naam
    and upper(ppa.segment1)                                like nvl(upper('%&project%'),upper(ppa.segment1))    -- project nummer
    and upper(pt.task_number)                              like nvl(upper('%&taak%'),upper(pt.task_number)) -- taak nummer
    and upper(haou1.NAME)                                  like nvl(upper('%&Emp_org%'),upper(haou1.NAME)) -- organisatie medewerker
    and upper(haou.NAME)                                   like nvl(upper('%&Pro_org%'),upper(haou.NAME))   -- organisatie project order by htb1.start_time

    This long query is hardly readable. Please edit your original post and add tags [code] and [/code] around your select stament. Also use some indention to improve readability. The quality and speed of answers largely depends on that.

  • LEFT OUTER JOIN, Problem in POST-QUERY TRIGGER

    Hi,
    Please guide for the following
    I wrote below query in POST-QUERY Trigger of a TABULAR DATA BLOCK, having only one text item, called INVENTORY_ITEM
    select c.cat||' '||s.subcat||' '||l1.lvl1 ITEM INTO :DATABLOCK.INVENTORY_ITEM
    from itemcat c
    LEFT OUTER JOIN itemsubcat s on (c.catid = s.catid)
    LEFT OUTER JOIN lvl1 l1 on (s.subcatid = l1.subcatid)
    When I compile the module an error is generated
    *" Encountered the symbol 'LEFT' when expecting one of the following ,; for group having intersect minus order start union where connect ".*
    Above query is working fine in ORACLE SQL DEVELOPER .
    Any solution please.
    Regards,

    Difference

  • Generic connectivity to Sybase and outer join problem

    I have a need to query records from a Sybase database running on Linux
    (32-bit) and am using Oracle 10.2.0.3 with generic connectivity (no
    specific heterogeneous service/transparent gateway for Sybase on Linux, that I see). We have installed
    an ODBC driver on the Oracle server and can query the Sybase database
    without difficulty except for outer joins.
    I have tried using both the Oracle syntax and the ANSI syntax. Both
    return results that are consistent with using an inner join. The ANSI
    query, run directly against the Sybase database returns the correct
    data (of course, removing the database link syntax).
    I was looking into the possibility of using dbms_hs_passthrough, but
    it does not appear to be part of the generic connectivity.
    Is there a better/right way of doing this? Aren't outer joins supported?
    Thanks,
    Vince

    As a followup, I did get dbms_hs_passthrough working and am able to get the correct data back. However, I would like to leave this as a backup.
    Aren't outer joins supported in the generic connectivity?
    Vince

  • Issues with limit/filter on outer join table in BQY

    I'm converting a series of BQY's from Brio 6.6 to Hyperion 9.3. I have some questions about the "use ODBC outer join syntax on limits" option in the OCE. I sort of understand this option's purpose, but I don't completely understand the SQL I'm seeing. For example Brio 6.6 is generating the following SQL statement:
    SELECT * FROM tblA AL1 LEFT OUTER JOIN tblB AL38 ON (AL38.ParentID=AL1.ChildID AND
    AL38.Data='SomeData') WHERE ((NOT AL38.Action IS NULL))
    Now, Hyperion 9.3 generated the SQL statement as follows:
    SELECT * FROM tblA AL1 LEFT OUTER JOIN tblB AL38 ON (AL38.ParentID=AL1.ChildID AND
    AL38.Data='SomeData') AND (NOT AL38.Response IS NULL))
    My questions are:
    1) Why isn't the "NOT AL38.Action IS NULL" statement included in the outer join in Brio? My limited understanding of the "use ODBC outer join syntax on limits" seems to indicate that it should end up there. I want the SQL to look like this, but I don't know why Brio generates this SQL.
    2) How can I get Hyperion to generate the same SQL as Brio? And still use the OCE with "use ODBC outer join syntax on limits" selected?

    Setting the Cardinality of Department > Employee role to OptionalOne
    gives rise to cartesian join (which is a bigger issue).
    Therefore, the Cardinality of Department > Employee role should remain as
    OptionalMany (default).
    This means, the outer join problem still remains unsolved. I have, therefore,
    unmarked the above answer by me.
    The question is - why has Report Builder been designed in such a way that the primary entity is always the child entity when attributes are selected from both parent and child entities?
    Most people desire that all the rows of the parent entity be fetched irrespective of whether there are corresponding rows in the child entity or not. Report Builder tool should not dictate what the user wants to get, meaning it is not right to assume
    that the focus of the report is Employee when attributes are selected from both Department and Employee. Report Builder should not make the child entity (i.e., Employee) as the primary entity when the user selects attributes from the child entity after
    having selected attributes from the parent entity.
    I am sorry to say that clients may not accept the Report Builder tool as this does not fetch the records as desired.
    I hope there is someone who can suggest how the outer join problem can be solved by just tweaking the properties of the report model (SMDL).
    Besides, the end users are business users and are not tech savvy. They are not expected to modify queries. They would simply drag and drop attributes from entities to create adhoc reports.

  • Full outer join unexpected results

    Warning, long message - I've searched the forums and found nothing similar. I've cut out as much as possible. We have been given the following schema to work with:
    CREATE TABLE CALLS (
    TRUNKIN VARCHAR2 (10),
    TRUNKOUT VARCHAR2 (10),
    DURATION FLOAT)
    Here is some test data:
    insert into calls values(null, 'a', 3);
    insert into calls values(null, 'a', 2);
    insert into calls values('a', null, 1);
    insert into calls values(null, 'a', 0);
    insert into calls values(null, 'a', 0);
    insert into calls values(null, 'a', 7);
    insert into calls values(null, null, 0);
    This is horribly unnormalized, but basically this table represent phone calls. trunkin and trunkout represent the two ends, and duration is length of a call. While obviously every call has two ends, the nulls above represent ends we don't care about in this example.
    The goal is to end up with data that looks like this. In English, we want the in and out summary statistics for each trunk to be summarized into a single row. (Sorry, these are supposed to be columns, but they got wrapped, so I reposted them as rows):
    TRUNKIN a
    IN_CALLS_ATTEMPTED 1
    IN_CALLS_COMPLETED 1
    IN_AVERAGE_DURATION 1
    TRUNKOUT a
    OUT_CALLS_ATTEMPTED 5
    OUT_CALLS_COMPLETED 3
    OUT_AVERAGE_DURATION 4
    Indeed, with the data given above, these are the results returned with the query at the end of this message. However, when I changed the one non-null trunkin value to null, I got very strange results. First, I independently ran the two subqueries. The first of course returns no rows, the second returns 1 with the same out values above; this is exactly what I would expect. However, when I run the full query, I get **5** rows back, each with just the trunkout column set to "a" and **all** other columns set to null. This makes no sense to me. The 5 rows are obviously the 5 rows from the original data set where trunkout = "a", but I'm not full outer joining those; I'm full outer joining the result of the group by, which only has 1 row. But even given that I'm getting 5 rows back, shouldn't all five of those have the remaining out columns filled in with the values above?
    Here is the query:
    select
    from
    SELECT
    trunkin as trunk,
    COUNT(*) AS in_calls_attempted,
    SUM
    CASE
    WHEN duration > 0 THEN 1
    ELSE 0
    END
    ) AS in_calls_completed,
    SUM(duration)/
    SUM
    CASE
    WHEN duration > 0 THEN 1
    ELSE 0
    END
    ) AS in_average_duration
    FROM CALLS
    WHERE trunkin IS NOT NULL
    GROUP BY trunkin
    ) callsin
    full outer join
    SELECT
    trunkout as trunk,
    COUNT(*) AS out_calls_attempted,
    SUM
    CASE
    WHEN duration > 0 THEN 1
    ELSE 0
    END
    ) AS out_calls_completed,
    SUM(duration)/
    SUM
    CASE
    WHEN duration > 0 THEN 1
    ELSE 0
    END
    ) AS out_average_duration
    FROM CALLS
    WHERE trunkout IS NOT NULL
    GROUP BY trunkout
    ) callsout
    on callsin.trunk = callsout.trunk;

    I am not entirely sure why you are getting the results you are, but I strongly suspect that it is a result of outer joining on null columns. I would write the query as follows to avoid the outer join problem. The CASE statements in the outer query around the average duration calulations avoid the divide by zero error that would occur when some trunk has only in or out calls.
    SELECT trunk,SUM(in_calls_attempted) in_calls_attempted,
           SUM(in_calls_completed) in_calls_completed,
           CASE WHEN SUM(in_calls_completed) <> 0 THEN
                SUM(in_duration)/SUM(in_calls_completed)
                ELSE 0 END ave_in_duration,
           SUM(out_calls_attempted) out_calls_attempted,
           SUM(out_calls_completed) out_calls_completed,
           CASE WHEN SUM(out_calls_completed) <> 0 THEN
                SUM(out_duration)/SUM(out_calls_completed)
                ELSE 0 END ave_out_duration
    FROM (
       SELECT trunkin trunk,COUNT(*) in_calls_attempted,
              SUM(CASE WHEN duration > 0 THEN 1 ELSE 0 END) in_calls_completed,
              SUM(duration) in_duration,0 out_calls_attempted,
              0 out_calls_completed,0 out_duration
       FROM calls
       GROUP BY trunkin
       UNION ALL
       SELECT trunkout trunk,0 in_calls_attempted,0 in_calls_completed,
              0 in_duration,COUNT(*) out_calls_attempted,
              SUM(CASE WHEN duration > 0 THEN 1 ELSE 0 END) out_calls_completed,
              SUM(duration) out_duration
       FROM calls
       GROUP BY trunkout)
    GROUP BY trunkTTFN
    John

  • Outer Join issue in SSRS

    Symptom description:
    I have a Department table and an Employee table. In Department table, Deptno is the primary key. In Employee table, Empid is the primary key and Deptno is a foreign key pointing to Deptno of Department table.
    Using BIDS, I have created a Data Source View (DSV) incorporating the above two tables and a relationship is also formed where Employee is the source and Department is the destination. I have then autogenerated a Report Model (.smdl) using the DSV.
    Now, when I select attributes from both Department entity and Employee entity in Report Builder 3.0, the query generated by Report Builder fetches only those records from Department for which an employee exists.
    My objective is to fetch all records from Department when Department is joined with Employee irrespective of whether an employee exists or not for that department. How can this be achieved?
    Given below is the query generated by Report Builder:
    SELECT DISTINCT
        "DEPT"."DepartmentNo" "DepartmentNo",
        "DEPT"."DepartmentDepartmentName" "DepartmentDepartmentName",
        "DEPT"."City" "City",
        "EMP"."EMPID" "EmployeeID",
        "EMP"."EMP_NAME" "EmployeeName",
        "EMP"."SALARY" "Salary"
    FROM
        "CLINICOPIA_REPORTS"."EMP" "EMP"
        LEFT OUTER JOIN (
            SELECT /*+ NO_MERGE */
                "DEPT"."DEPTNO" "DepartmentNo",
                "DEPT"."DEPT_NAME" "DepartmentDepartmentName",
                "DEPT"."CITY" "City",
                "DEPT"."DEPTNO" "DEPTNO"
            FROM
                "CLINICOPIA_REPORTS"."DEPT" "DEPT"
        ) "DEPT" ON "EMP"."DEPTNO" = "DEPT"."DEPTNO"
    WHERE
        CAST(1 AS NUMERIC(1,0)) = 1
    ORDER BY
        "DepartmentNo", "DepartmentDepartmentName", "City", "EmployeeID", "EmployeeName", "Salary";
    Environment: SharePoint 2010 serves as the Web Front-End Server and also hosts Reporting Services Add-in. SQL Server 2008 R2 SP2 is the Back-End Server hosting Sql Server Reporting Services
    (SSRS) in SharePoint Integrated mode. The data is fetched in the Report Builder 3.0 reports from an Oracle database.
    Environment details-
    Web Front-End Server: SharePoint Server 2010 with Enterprise Client Access License features. Operating System is Microsoft Windows Server 2008 R2 Standard - 64 Bit.
    Back-End Database Server: SQL Server 2008 R2 Enterprise SP2. Operating System is Microsoft Windows Server 2008 R2 Standard - 64 Bit.
    Oracle Database Server: Operating System is Red Hat Enterprise Linux Server release 5 (Tikanga). Oracle Database version is Oracle Database 10g R2 Enterprise Edition Release 10.2.0.2.0 - Production.

    Setting the Cardinality of Department > Employee role to OptionalOne
    gives rise to cartesian join (which is a bigger issue).
    Therefore, the Cardinality of Department > Employee role should remain as
    OptionalMany (default).
    This means, the outer join problem still remains unsolved. I have, therefore,
    unmarked the above answer by me.
    The question is - why has Report Builder been designed in such a way that the primary entity is always the child entity when attributes are selected from both parent and child entities?
    Most people desire that all the rows of the parent entity be fetched irrespective of whether there are corresponding rows in the child entity or not. Report Builder tool should not dictate what the user wants to get, meaning it is not right to assume
    that the focus of the report is Employee when attributes are selected from both Department and Employee. Report Builder should not make the child entity (i.e., Employee) as the primary entity when the user selects attributes from the child entity after
    having selected attributes from the parent entity.
    I am sorry to say that clients may not accept the Report Builder tool as this does not fetch the records as desired.
    I hope there is someone who can suggest how the outer join problem can be solved by just tweaking the properties of the report model (SMDL).
    Besides, the end users are business users and are not tech savvy. They are not expected to modify queries. They would simply drag and drop attributes from entities to create adhoc reports.

  • ORA-01799: a column may not be outer-joined to a subquery

    Hi,
    How to solve this problem below?
         and id2.invoice_line_id*(+)*=(select min(invoice_line_id)
              from TW.invoice_detail
              where invoice_id=239917
              and (bl_amount_currency='USD' AND actual_amount_currency='VND'
              OR bl_amount_currency='VND' AND actual_amount_currency='USD')
    ERROR at line 150:
    ORA-01799: a column may not be outer-joined to a subquery
    Since there's an uncertain existence in id2, it needs to be outer-joined to that!
    Bst Rgds,
    HuaMin

    You cant do a outer join on a sub query. Can you describe what are you trying to do?

Maybe you are looking for