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

Similar Messages

  • 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!!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • CORRELATED SUB QUERY IN OBIEE

    Hi Experts,
    How to achieve correlated sub query in OBIEE
    Example for correlated sub query is here:
    SELECT
    HR_EMPLOYEE_DIM.EMPLID,
    HR_EMPLOYEE_DIM.NAME,
    HR_EMPLOYEE_DIM.JOBCODE_CD,
    HR_EMPLOYEE_DIM.JOBCODE_DESC,
    FROM
    HR_EMPLOYEE_DIM,
    EMPLOYEE_ACTION_FACT
    WHERE
    ( EMPLOYEE_ACTION_FACT.HR_EMPLOYEE_KEY=HR_EMPLOYEE_DIM.HR_EMPLOYEE_KEY )
    AND
    ( to_char(EMPLOYEE_ACTION_FACT.PS_EFF_DT,'yyyymmdd') || EMPLOYEE_ACTION_FACT.PS_EFF_SEQ=
    (SELECT MAX(TO_CHAR(PS_EFF_DT,'yyyymmdd')|| PS_EFF_SEQ)
    FROM
    EMPLOYEE_ACTION_FACT EAF1,
    HR_EMPLOYEE_DIM HED1
    WHERE EAF1.HR_EMPLOYEE_KEY = HED1.HR_EMPLOYEE_KEY
    AND HED1.PS_EMPLID = HR_EMPLOYEE_DIM.PS_EMPLID
    Thanks
    Naresh
    Edited by: Naresh Meda on Dec 2, 2008 5:52 AM

    But I want to pass presentation variable for the second query.
    Regards
    Naresh
    Edited by: Naresh Meda on Dec 2, 2008 10:27 PM

  • Correlated Sub Query

    Deal All,
    Please help me to know list of Drawback/Limitation of Corellated Subquery.
    i want to Optimize the correlated sub Query.
    Thanks,
    Dinesh Babu
    9818783322

    See:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:3167884300346662300
    It would be nice to know your database version.
    It would be nice to know what query you're executing
    It would be nice to see an execution plan
    It would be nice if you'd first read the SQL and PL/SQL FAQ, especially:
    SQL and PL/SQL FAQ
    and
    *3. How to improve the performance of my query? / My query is running slow*.
    When your query takes too long...
    How to post a SQL statement tuning request
    SQL and PL/SQL FAQ

  • 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

  • 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

  • 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?

  • 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.

  • 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.

  • 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.

  • Adhoc Query Outer Join

    Hi
    Is it possible to have adhoc queries with outer join since logical databases use inner joins.. Was just wondering if this is possible
    Thanks
    Case

    Hi
    As workaround u can use the SQVI - Query where u can play with infotype .
    you can select wat are the infotypes to be joined and wat are the filedls u wish to get out put and selection everthing
    with regards
    partha
    keep sharing and learing

  • 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

  • Peoplesoft Query Outer join with MAX EFFDT

    I have this criteria in my PS Query
    where A.emplid = B.emplid
    and B.effdt = (select max( B1.effdt ) from PS_TABLE_B B1 where B1.effdt <= SYSDATE )
    Need to do an OUTER JOIN for B.
    Ie. If no row found in B, then return blank so that row in A can be returned by query.
    It's OK for A.emplid = B.emplid(+)
    But how to approach for and B.effdt = (select max ... ?
    Please advise

    If I remember it right, if you write outer joins using ( + ), there shouldn't be any other non-outer join criteria in your SQL, otherwise it will negate its being an 'outer join'.
    so for your (1) this highlighted SQL block negates your 'outer join' condition
    AND A.EMPLID =  C.EMPLID(+)
    AND ( C.EFFDT = (SELECT MAX( D.EFFDT)
                             FROM PS_D D
                            WHERE D.EMPLID = C.EMPLID
                              AND D.ACTION_REASON = 'MAT'
                              AND ( D.RETURN_DT IS NULL OR D.RETURN_DT > SYSDATE))
                OR C.EFFDT IS NULL) )
    you should see more from here http://docs.oracle.com/cd/B28359_01/server.111/b28286/queries006.htm#SQLRF52336
    From that article, it says.. "If A and B are joined by multiple join conditions, then you must use the operator in all of these conditions. If you do not, then Oracle Database will return only the rows resulting from a simple join, but without a warning or error to advise you that you do not have the results of an outer join."
    What I suggest, create a SQL view to replace C that retrieves exactly what C has to retrieve.. probably something like this
    SELECT D.*
    FROM PS_D D
    WHERE D.ACTION_REASON = 'MAT'
      AND( D.RETURN_DT IS NULL OR D.RETURN_DT > SYSDATE )
      AND D.EFFDT = (SELECT MAX(EFFDT) ... )
    and reference that new SQL view for C.. so that in your query, it should only look something like
    AND A.EMPLID = C.EMPLID(+)
      AND( C.EFFDT =
      (SELECT MAX( D.EFFDT )
         FROM PS_D D
        WHERE D.EMPLID = C.EMPLID
        AND D.ACTION_REASON = 'MAT'
        AND( D.RETURN_DT IS NULL
        OR D.RETURN_DT > SYSDATE )
      OR C.EFFDT IS NULL ) )
    Hope this helps

  • 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

  • Complex query/subquery/join problem

    Hi,
    i need to retrieve information from our database in one single dataset but i can't get it all together...
    Here's the situation:
    We have several linked tables:
    Workorder (wo_operation)
    -woo_key
    Workorder_task (wo_task)
    -wot_key -> PK
    -woo_key -> FK_woo
    Workorder_task_labor (wo_task_labor)
    -wtl_key -> PK
    -wot_key -> FK_wot
    -start_time -> essential field
    I'm running a query which retrieves records from the Workorder (wo_operation) table like this (this one works nicely, don't mind the other joins):
    SELECT
    rownum num,
    woo.woo_auto_key,
    woo.si_number,
    apc.application_code,
    cmp.company_name,
    woo.company_ref_number,
    view_wo.serial_number,
    view_wo.part_number,
    view_wo.description part_description,
    wos.description status_description
    FROM (((((wo_operation woo INNER JOIN view_spb_wo_maincomponent view_wo ON woo.woo_auto_key = view_wo.woo_auto_key)
    LEFT JOIN wo_status wos ON woo.wos_auto_key = wos.wos_auto_key)
    INNER JOIN parts_master pnm ON woo.pnm_auto_key = pnm.pnm_auto_key)
    INNER JOIN application_codes apc ON pnm.apc_auto_key = apc.apc_auto_key)
    INNER JOIN companies cmp ON woo.cmp_auto_key = cmp.cmp_auto_key)
    WHERE woo.wos_auto_key IS NULL OR woo.wos_auto_key not IN (2, 10)
    Now here's the problem. I need to add one more column which shows the last task (max(wo_task_labor.start_time)) that people have been working on (wo_task.description).
    Wo_task is linked to wo_operation on WOO_KEY (many TO one)
    Wo_task_labor is linked to Wo_task on WOT_KEY (zero or many TO one)
    So I need to find the MAX wo_task_labor.START_TIME and then Select the wo_task.description with that start_time. BUT since the relation is ZERO OR MORE to ONE it could be that there isn't even a START_TIME available for Max() function.......
    Is there anybody who could send me in the right direction???

    Hmmz ok, I just finished a more readable problem description.. Were you absolutely certain that my problem needs another approach?
    here's the problem again:
    Situation:
    wo_operation
    | Woo_auto_key | Si_number |
    | 1            | w100      |
    | 2            | w105      |
    | 3            | w200      |
    wo_task
    | Wot_auto_key | Woo_auto_key | Description |
    | 1            | 1            | OPENING     |
    | 2            | 1            | INSPECT     |
    | 3            | 2            | OPENING     |
    | 4            | 2            | REJECT      |
    | 5            | 3            | OPENING     |
    Wo_task_labor
    | Wtl_auto_key | Wot_auto_key | Start_time | Stop_time |
    | 1            | 1            | 7:00       | 7:05      |
    | 2            | 1            | 11:45      | 12:00     |
    | 3            | 2            | 10:00      | 10:15     |
    | 4            | 2            | 11:00      | 11:20     |
    | 5            | 2            | 11:35      | 11:40     |
    | 6            | 3            | 9:00       | 9:15      |
    | 7            | 3            | 9:30       | 9:40      |
    | 7            | 3            | 9:45       | 9:50      |
    | 8            | 4            | 9:00       | 10:00     |
    | 9            | 4            | 10:15      | 10:30     |
    Query:
    SELECT
         woo.si_number
    FROM
         wo_operation woo
    Result:
    | SI_NUMBER |
    | w100      |
    | w105      |
    | w200      |
    My needed result:
    | SI_NUMBER | DESCRIPTION      |
    | w100      | OPENING          | -> last labor is wtl_auto_key 2 from 11:45 to 12:00
    | w105      | REJECT           | -> last labor is wtl_auto_key 9 from 10:15 to 10:30
    | w200      | (null) or 'none' | -> last labor is not available since there is no labor record
    How can this be done querywise?
    Message was edited by:
    user574699

Maybe you are looking for