Outer join - null values

How can i distinguish in an outer join between rows from the right hand table which is in existance but all components are initial and rows from the right hand table which are not in existance?

Hi,
Try incorporating the key from the right hand table this should ideally not be initial. Or maybe you could incorporate the MANDT field from the right hand table.
Che

Similar Messages

  • Need help Take out the null values from the ResultSet and Create a XML file

    hi,
    I wrote something which connects to Database and gets the ResultSet. From that ResultSet I am creating
    a XML file. IN my program these are the main two classes Frame1 and ResultSetToXML. ResultSetToXML which
    takes ResultSet & Boolean value in its constructor. I am passing the ResultSet and Boolean value
    from Frame1 class. I am passing the boolean value to get the null values from the ResultSet and then add those
    null values to XML File. When i run the program it works alright and adds the null and not null values to
    the file. But when i pass the boolean value to take out the null values it would not take it out and adds
    the null and not null values.
    Please look at the code i am posing. I am showing step by step where its not adding the null values.
    Any help is always appreciated.
    Thanks in advance.
    ============================================================================
    Frame1 Class
    ============
    public class Frame1 extends JFrame{
    private JPanel contentPane;
    private XQuery xQuery1 = new XQuery();
    private XYLayout xYLayout1 = new XYLayout();
    public Document doc;
    private JButton jButton2 = new JButton();
    private Connection con;
    private Statement stmt;
    private ResultSetToXML rstx;
    //Construct the frame
    public Frame1() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    //Component initialization
    private void jbInit() throws Exception {
    //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
    contentPane = (JPanel) this.getContentPane();
    xQuery1.setSql("");
    xQuery1.setUrl("jdbc:odbc:SCANODBC");
    xQuery1.setUserName("SYSDBA");
    xQuery1.setPassword("masterkey");
    xQuery1.setDriver("sun.jdbc.odbc.JdbcOdbcDriver");
    contentPane.setLayout(xYLayout1);
    this.setSize(new Dimension(400, 300));
    this.setTitle("Frame Title");
    xQuery1.setSql("Select * from Pinfo where pid=2 or pid=4");
    jButton2.setText("Get XML from DB");
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    catch(java.lang.ClassNotFoundException ex) {
    System.err.print("ClassNotFoundException: ");
    System.err.println(ex.getMessage());
    try {
    con = DriverManager.getConnection("jdbc:odbc:SCANODBC","SYSDBA", "masterkey");
    stmt = con.createStatement();
    catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    jButton2.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    jButton2_actionPerformed(e);
    contentPane.add(jButton2, new XYConstraints(126, 113, -1, -1));
    //Overridden so we can exit when window is closed
    protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
    System.exit(0);
    void jButton2_actionPerformed(ActionEvent e) {
    try{
    OutputStream out;
    XMLOutputter outputter;
    Element root;
    org.jdom.Document doc;
    root = new Element("PINFO");
    String query = "SELECT * FROM PINFO WHERE PID=2 OR PID=4";
    ResultSet rs = stmt.executeQuery(query);
    /*===========This is where i am passing the ResultSet and boolean=======
    ===========value to either add the null or not null values in the file======*/
    rstx = new ResultSetToXML(rs,true);
    } //end of try
    catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    ======================================================================================
    ResultSetToXML class
    ====================
    public class ResultSetToXML {
    private OutputStream out;
    private Element root;
    private XMLOutputter outputter;
    private Document doc;
    // Constructor
    public ResultSetToXML(ResultSet rs, boolean checkifnull){
    try{
    String tagname="";
    String tagvalue="";
    root = new Element("pinfo");
    while (rs.next()){
    Element users = new Element("Record");
    for(int i=1;i<=rs.getMetaData().getColumnCount(); ++i){
    tagname= rs.getMetaData().getColumnName(i);
    tagvalue=rs.getString(i);
    System.out.println(tagname);
    System.out.println(tagvalue);
    /*============if the boolean value is false it adds the null and not
    null value to the file =====================*/
    /*============else it checks if the value is null or the length is
    less than 0 and does the else clause in the if(checkifnull)===*/
    if(checkifnull){ 
    if((tagvalue == null) || tagvalue.length() < 0 ){
    users.addContent((new Element(tagname).setText(tagvalue)));
    else{
    users.addContent((new Element(tagname).setText(tagvalue)));
    else{
    users.addContent((new Element(tagname).setText(tagvalue)));
    root.addContent(users);
    out=new FileOutputStream("c:/XMLFile.xml");
    doc = new Document(root);
    outputter = new XMLOutputter();
    outputter.output(doc,out);
    catch(IOException ioe){
    System.out.println(ioe);
    catch(SQLException sqle){

    Can someone please help me with this problem
    Thanks.

  • How to find out the null values in table

    hi experts,
    my version is oracledb10g:
    i h'd simple doubts.
    for eg:
    create table ex1( e varchar2(20));
    insert into ex1 (null).
    insert into ex1(e)
    count will be: 2
    i can easily found out the value 'e'.
    so my question is:
    how can i found out the null values in the table and i want to delete the null values from the table.

    ADF 7 wrote:
    hi experts,
    my version is oracledb10g:
    i h'd simple doubts.
    for eg:
    create table ex1( e varchar2(20));
    insert into ex1 (null).
    insert into ex1(e)
    count will be: 2That depends what you count. If you issue count(*) you are asking Oracle "how many rows are there". If you issue a count(<column_name>) you are asking Oracle "how many not null values of <column_name> are there".
    ADF 7 wrote:
    i can easily found out the value 'e'.
    so my question is:
    how can i found out the null values in the table and i want to delete the null values from the table.
    delete from <table_name>
    where <column_name> is null;Ideally you'd just place a NOT NULL constraint on the column in question, thereby prohibiting NULL values from entering into the system (assuming your business requirement is that the column MUST always have a value).

  • SQL Select using LEFT OUTER JOIN returning field values when I expect NULL

    I am having problems with this select statement:
    SELECT distinct pl.id, th.trip, pc.country, pph.location
    FROM people_list pl, people_travelhistory th, people_country pc
    LEFT OUTER JOIN people_info pph on pph.id=pl.id and pph.country=pc.country
    where people_list.active='Y' and people_list.id=th.id and th.trip = pc.trip;
    The criteria is that the pph table may not have no record for that id and country.
    The problem is that the pph.location field is returned with data even when no matching record for that id or country exists.
    If the record doesn't exist in the pph table, I want pph.location = NULL
    What am I doing wrong?
    Thanks in Advance!
    Developer

    Hi, You can try this :
    SELECT distinct pl.id, th.trip, pc.country, pph.location
    FROM people_list pl, people_travelhistory th, people_country pc
    left outer join people_info pph on pph.id = pl.id
    left outer join people_country pc on pc.country = pph.country
    left outer join people_travelhistory th on th.id = pl.id
    where pl.active='Y' and th.trip = pc.trip;
    Knowing that you requesting people active that have travelled to their own country.
    Regards

  • Defaulting Null Values in an outer join to the last joined row's values.

    I have a situation where I need to fill in the missing values from an outer join with the last values returned by the join.
    The query is based on a date table, an organization table and a transaction table.
    SELECT D.DATE_ID, O.ORG_ID, T.VALUE
    FROM D_ORGANIZATION O, D_DATE D, F_TRANSACTION T
    WHERE D.DATE_ID = T.DATE_ID(+)
    AND T.ORG_ID = O.ORG_ID(+)
    AND O.ORG_NAME = '&NAME'[
    AND D.THE_DATE >= ADD_MONTHS( TO_DATE( '&&PERIOD_DATE', 'DD-MON-YYYY' ), -23 )
    AND D.THE_DATE <= ADD_MONTHS( TO_DATE( '&&PERIOD_DATE', 'DD-MON-YYYY' ), 24 )
    So the query will return all dates in the 4 year period, and where transactions exist the relevent value.
    DATE_ID ORG_ID VALUE
    38291     2 99.8
    38321     2 45.1
    38352     
    38383     
    38411     
    What I need to happen is:
    DATE_ID ORG_ID VALUE
    38291     2 99.8
    38321     2 45.1
    38352     2 45.1     
    38383 2 45.1
    38411     2 45.1
    Lag appears to be of no use because it will only pick up the last genuine value, so using
    NVL(T.VALUE, LAG(T.VALUE,1) OVER ( .... )
    Gives:
    ATE_ID ORG_ID VALUE
    38291     2 99.8
    38321     2 45.1
    38352     2 45.1     
    38383
    38411     
    The length of the data gap can vary as constituent organisations don't all return their data at the same time, and there may be intermediate dates where no data is returned , but the value needs to be calculated.
    What's going on here is that a gaph is being generated where the tool requires data points to plot the line, once the real data ends a bespoke trend calculations takes over based on the last value returned. I do not have access to the data warehousing options so a solution that doen't need them would be handy, but if not then options can be purchased.
    The tool can't use PL/SQL, but is perhaps a bespoke function in order?

    To do this wouldn't you need to know the data in advance? The real source table had 1800 organisations and 8,000,000 transactions.
    I Tried this as well, creating a pl/sql package as follows.
    create or replace PACKAGE stack AS
    TYPE gnt_push_numbers IS TABLE OF NUMBER INDEX BY PLS_INTEGER;
    TYPE gvt_push_varchars IS TABLE OF VARCHAR(1000) INDEX BY PLS_INTEGER;
    gna_push_numbers gnt_push_numbers;
    gva_push_varchars gvt_push_varchars;
    FUNCTION PUSH ( pn_push_var NUMBER, pn_offset NUMBER) RETURN NUMBER DETERMINISTIC;
    FUNCTION PUSH ( pv_push_var VARCHAR, pn_offset NUMBER) RETURN VARCHAR DETERMINISTIC;
    FUNCTION POP_NUM ( pn_offset NUMBER) RETURN NUMBER DETERMINISTIC;
    FUNCTION POP_VAR ( pn_offset NUMBER) RETURN VARCHAR DETERMINISTIC;
    END stack;
    CREATE OR REPLACE
    PACKAGE BODY "STACK" AS
    FUNCTION push(pn_push_var NUMBER, pn_offset NUMBER) RETURN NUMBER deterministic IS
    BEGIN
    gna_push_numbers(pn_offset) := pn_push_var;
    RETURN pn_push_var;
    END push;
    FUNCTION push(pv_push_var VARCHAR, pn_offset NUMBER) RETURN VARCHAR deterministic IS
    BEGIN
    gva_push_varchars(pn_offset) := pv_push_var;
    RETURN pv_push_var;
    END push;
    FUNCTION pop_num(pn_offset NUMBER) RETURN NUMBER deterministic IS
    BEGIN
    RETURN gna_push_numbers(pn_offset);
    END pop_num;
    FUNCTION pop_var(pn_offset NUMBER) RETURN VARCHAR deterministic IS
    BEGIN
    RETURN gva_push_varchars(pn_offset);
    END pop_var;
    END stack;
    Unfortunately it appears to act before the rows are sorted, so will only work in specialised circumstances, in that you have to ensure the rows have been sorted before the function is used.
    SELECT PUSH(COL), POP..(COL)
    FROM ( SELECT etc.
    Luckily the client decided they didn't want to mix their graphs any more so a more classic approach using a base table select for actuals and then a date table select with a sub-query columns for the projection provided a simple solution.

  • ORA-22922: nonexistent LOB value in outer join in XMLDB parsing query

    Hi,
    We are in a situation where i must use outer join with the address type fragment in the XML reader query,
    Here is the oracle installation details
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    "CORE     11.2.0.3.0     Production"
    However once i add the (+) sign i get an error, other wise it runs absolutely fine without the (+) s
    ORA-29400: data cartridge error
    ORA-22922: nonexistent LOB value
    29400. 00000 - "data cartridge error\n%s"
    *Cause:    An error has occurred in a data cartridge external procedure.
    This message will be followed by a second message giving
    more details about the data cartridge error.
    *Action:   See the data cartridge documentation
    for an explanation of the second error message.
    Query:
    =======
    select
    from PWAYWORKFILE_TABLE,
    xmltable(
    xmlnamespaces(DEFAULT 'http://www.cccis.com/Pathways/Workfile'
    , 'http://www.cccis.com/Pathways/CommonType' as "pct")
    , '$XS/PwayWorkfile' passing WORKFILE as "XS"
    columns
    CURESTID VARCHAR2 (4000) PATH 'EstimateComp/LastOutboxEstID',
    Est_Fragment XMLTYPE PATH 'EstimateComp/EstList/VehEstimate'
    ) m,
    XMLTABLE(
    xmlnamespaces(DEFAULT 'http://www.cccis.com/Pathways/Workfile'
    , 'http://www.cccis.com/Pathways/CommonType' as "pct")
    , '$PY/VehEstimate' passing m.Est_Fragment as "PY"
    columns
    NUMBERLINES VARCHAR2 (4000) PATH '@NumberLines',
    LINEESTIMATEID VARCHAR2 (4000) PATH 'EstimateID',
    EstLine_Fragment XMLTYPE PATH 'EstimateLines/EstimateLine'
    ) (+) l,
    XMLTABLE(
    xmlnamespaces(DEFAULT 'http://www.cccis.com/Pathways/Workfile'
    , 'http://www.cccis.com/Pathways/CommonType' as "pct")
    , '$NY/EstimateLine' passing l.EstLine_Fragment as "NY"
    columns
    LINENUMBER VARCHAR2 (4000) PATH '@LineNumber',
    LINEBLOCKID VARCHAR2 (4000) PATH 'LineBlockID',
    LABORCATEGORY VARCHAR2 (4000) PATH 'LaborCategory',
    LABORHOURS VARCHAR2 (4000) PATH 'LaborHours',
    LINEOPERATION VARCHAR2 (4000) PATH 'LineOperation',
    MANUALLABORINCLUDE VARCHAR2 (4000) PATH 'ManualLaborInclude',
    MANUALPAINTINCLUDE VARCHAR2 (4000) PATH 'ManualPaintInclude',
    MANUALPRICEINCLUDE VARCHAR2 (4000) PATH 'ManualPriceInclude',
    OEMPRICE VARCHAR2 (4000) PATH 'Calculation/OEMPrice',
    SINGLEOHINCL VARCHAR2 (4000) PATH 'DataList/DBMotorData/LaborInclType/@SINGLEOHINCL',
    DOUBLEOHINCL VARCHAR2 (4000) PATH 'DataList/DBMotorData/LaborInclType/@DOUBLEOHINCL',
    PPAGEINCL VARCHAR2 (4000) PATH 'DataList/DBMotorData/LaborInclType/@PPAGEINCL',
    SUPPLIERID VARCHAR2 (4000) PATH 'DataList/RPSPart/SupplierID'
    ) (+) j
    where
    l.LINEESTIMATEID = 51 or
    l.LINEESTIMATEID = m.CURESTID or
    l.LINEESTIMATEID = (CASE
    WHEN m.CURESTID = 101 THEN 51
    WHEN m.CURESTID > 101 THEN m.CURESTID -1
    ELSE -1 END);
    Please note that the PWAYWORKFILE_TABLE is objection relationally stored with XMLs.
    Please suggest what kind of error i am getting and what possible steps might resolve the same, let me know if i missed any details which might shade more light on the same.
    Regards,
    Arghyadip

    Which outer join gives you the error? I don't see any address information in the SQL, hence my question. The first outer join, on table alias L is not needed. The WHERE clause you have setup requires that L.LINEESTIMATEID has a value and so NULL will not evaluate to TRUE and the row will be filtered out. This means you will only be returning rows where there exists rows in the L table, hence the outer join is not needed.
    Are all your columns really VARCHAR2(4000)? You say it is object-relational, but was something defined as a CLOB?
    You did not provide much in order to duplicate your error so I am just guessing at causes to identify the error.
    Also see #9 in
    {message:id=9360002}

  • Outer join With a constant value

    Hi all,
    In one of query i have found out that the outer join with a constant value like
    to_currency(+)='USD'
    to_currency is a column name in a table.can any one please explain this outer join condtn.
    Thanks in advance
    Senthil

    Hallo,
    if you write var (+) = constant
    var can be equal constant, and also can be null
    Compare these 2 queries
    select e.* from scott.emp e, scott.dept d
    where e.deptno = d.deptno(+)
    and d.deptno(+) = 10EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    7369     SMITH      CLERK      7902     17-Dez-1980     800          20
    7499     ALLEN      SALESMAN      7698     20-Feb-1981     1600     300     30
    7521     WARD      SALESMAN      7698     22-Feb-1981     1250     500     30
    7566     JONES      MANAGER      7839     2-Apr-1981     2975          20
    7654     MARTIN      SALESMAN      7698     28-Sep-1981     1250     1400     30
    7698     BLAKE      MANAGER      7839     1-Mai-1981     2850          30
    7782     CLARK      MANAGER      7839     9-Jun-1981     2450          10
    7788     SCOTT      ANALYST      7566     19-Apr-1987     3000          20
    7839     KING      PRESIDENT           17-Nov-1981     5000          10
    7844     TURNER      SALESMAN      7698     8-Sep-1981     1500     0     30
    7876     ADAMS      CLERK      7788     23-Mai-1987     1100          20
    7900     JAMES      CLERK      7698     3-Dez-1981     950          30
    7902     FORD      ANALYST      7566     3-Dez-1981     3000          20
    7934     MILLER      CLERK      7782     23-Jan-1982     1300          10
    select e.* from scott.emp e, scott.dept d
    where e.deptno = d.deptno(+)
    and d.deptno = 10 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    7782     CLARK      MANAGER      7839     9-Jun-1981     2450          10
    7839     KING      PRESIDENT           17-Nov-1981     5000          10
    7934     MILLER      CLERK      7782     23-Jan-1982     1300          10
    As you can see, this (+) is very important
    Regards
    Dmytro

  • Outer join doesn't retrieve the correct values

    Hi, I have a problem to retrieve some data from this query with the outer join:
    select count(incident_id),range_2 from
    (select range_2 from apps.aaa_table) a,
    (Select inc.incident_id,
    XXN2B_RESOLUTION_RANGE(2,ROUND(( (TO_DATE(inc.INCIDENT_ATTRIBUTE_7,'dd/mm/yyyy hh24:mi:ss')-inc.INC_RESPONDED_BY_DATE)*24 ),2)) RANGES
    ,inc.CATEGORY_ID
    , inc.INVENTORY_ITEM_ID,
    prom_dt.Iptv_Sumptom --S?µpt?µa
    FROM cs_incidents_all_b inc,
    cs_incidents_all_tl tl,
    cs_sr_type_mapping m,
    fnd_responsibility resp,
    xxntt.xxntt_incidents_support ntt,
    xxntt.xxntt_incidents ntt_inc,
    xxe.xxe_tt_promitheas_dt prom_dt,
    xxe.Xxe_Cs_Int_Sla sla
    WHERE inc.incident_id = tl.incident_id
    AND tl.LANGUAGE = 'EL'
    AND inc.incident_type_id = m.incident_type_id
    AND resp.responsibility_key IN (select SV.FLEX_VALUE from fnd_flex_value_sets s, FND_FLEX_VALUES SV
    where s.FLEX_VALUE_SET_NAME = 'XXNTT_RESPONSIBILITIES'
    AND S.FLEX_VALUE_SET_ID = SV.FLEX_VALUE_SET_ID)
    AND m.responsibility_id = resp.responsibility_id
    AND resp.end_date is null
    AND inc.incident_number = ntt.incident_number(+)
    AND inc.incident_number = ntt_inc.incident_number(+)
    AND inc.incident_id = prom_dt.incident_id(+)
    AND inc.incident_number = sla.Incident_Number(+)
    --and TOTAL_INACT_SLA_DURATION  not like '%0:00%'
    and (inc.INC_RESPONDED_BY_DATE is not null AND INCIDENT_ATTRIBUTE_7 is not null)
    ) b,
    (select * from xxntt_custom_hierarchy
    union
    select null eidos, null omada, null product_categiory, null category_id, null inv_item_descripiption, null symptom, null tautopoihsh, null inv_item_id from dual
    ) c
    where a.range_2 = b.ranges (+)
    and c.INV_ITEM_ID (+) = b.INVENTORY_ITEM_ID
    and c.CATEGORY_ID (+) = b.CATEGORY_ID
    and c.SYMPTOM (+) = b.IPTV_SUMPTOM
    and c.OMADA = 'A'
    group by range_2
    This query is composed by 3 dataset: a, b, and c
    the dataset a is a fixed list of values (LOV): range_2 = '0-2h','2-4h','4-6h','6-8h','8-10h','10-12h','12-14h','14-16h','16-18h','18-20h'
    the dataset b retrieve the list of the incident_id's and their related ranges (calculated with the function XXN2B_RESOLUTION_RANGE)
    the dataset c is just a filter on the the dataset b to retrieve only the incident_id's who belong to the Group 'A'
    Want I want to achieve is this: see always the complete list of values 'range_2' even if I don't have incident_id with a particular range.
    For this reason I put the condition: a.range_2 = b.ranges (+)
    ....but this doesn't work....I see ONLY the incident_id which have the range inside the LOV......instead I want to see also if there are incident_id without a range in the LOV.
    Grouping by range_2, I see:
    !http://www.freeimagehosting.net/uploads/d900035c11.jpg!
    instead of
    !http://www.freeimagehosting.net/uploads/99a75dfca4.jpg!
    Anybody can help me to understand where is the mistake ???
    Thanks in advance
    Alex

    Hi, Alex,
    Whenever you ask a question, post a little sample data (CREATE TABLE and INSERT statements) for all the tables (relevant columns only), as well as the results you want from that data.
    When you post formatted text on this site (and code should always be formatted) type these 6 characters:
    &#123;code&#125;
    (small letters only, inside curly brackets) before and after sections of formatted text, to preserve spacing.
    If you're using a + sign next to some column from table c, then all conditions involving table c need to have a + sign; otherwise, you cancel the effect of the outer join.
    Change
    and     c.OMADA      = 'A'to
    and     c.OMADA (+)  = 'A'That may be all you need. If not, post the sample data and your formatted query.

  • Using Command to fix null / left outer join issue

    Hi
    I was told awhile ago that it's possible to fix crystal's issue with left outer join and null records being eliminated.
    I think i remember most of how this goes, but i can't seem to duplicate it.
    1) You can't have any select expert -- record
    2) You create the report normally and then make a new report using the SQL Query
         - Can't remember if its the whole report or upto the tables that have hisotry (null results)
    3) You move parts from WHERE to FROM
    Hopefully someone can help correct the steps i'm doing wrong or add what i'm missing from this.
    Below is the Query from my comlpeted report, but when i run it with the last LEFT OUTER JOIN added it removes all the products with no sales during that year.
    Any help would be greatly appreciated even if it's to say this can't be done.
    SELECT
    "prod_warehouse"."pw_whs_id",
    "prod_warehouse"."pw_prodline_id",
    "prod_warehouse"."pw_prod_id",
    "prod_warehouse"."pw_bin_location1",
    "prod_warehouse"."pw_min_onhand_qty",
    "prod_warehouse"."pw_max_onhand_qty",
    "prod_warehouse"."pw_onhand_qty",
    "product_lookup"."prlkp_lang1_1_desc",
    "prod_customer"."prcu_cust_part_num",
    "contract_details"."cond_level1_amt",
    "sales_history"."sah_year"
    FROM   (((("sisl_data05"."dbo"."products" "products"
    LEFT OUTER  JOIN "sisl_data05"."dbo"."prod_warehouse" "prod_warehouse"
    ON ("products"."pr_prod_id"="prod_warehouse"."pw_prod_id")
    AND ("products"."pr_prodline_id"="prod_warehouse"."pw_prodline_id"))
    LEFT OUTER JOIN "sisl_data05"."dbo"."product_lookup" "product_lookup"
    ON ("products"."pr_prod_id"="product_lookup"."prlkp_prod_id")
    AND ("products"."pr_prodline_id"="product_lookup"."prlkp_prodline_id"))
    LEFT OUTER JOIN "sisl_data05"."dbo"."prod_customer" "prod_customer"
    ON ("products"."pr_prod_id"="prod_customer"."prcu_prod_id")
    AND ("products"."pr_prodline_id"="prod_customer"."prcu_prodline_id"))
    LEFT OUTER JOIN "sisl_data05"."dbo"."contract_details" "contract_details"
    ON "prod_warehouse"."pw_prod_id"="contract_details"."cond_prod_id")
    LEFT OUTER JOIN "sisl_data05"."dbo"."sales_history" "sales_history"
    ON (("prod_warehouse"."pw_whs_id"="sales_history"."sah_sortkey1")
    AND ("prod_warehouse"."pw_prod_id"="sales_history"."sah_sortkey2"))
    AND ("prod_warehouse"."pw_prodline_id"="sales_history"."sah_sortkey3")
    WHERE
    "prod_warehouse"."pw_whs_id"='20123'
    AND ("prod_warehouse"."pw_onhand_qty"<>0
    OR "prod_warehouse"."pw_bin_location1"<>'  '
    OR "prod_warehouse"."pw_max_onhand_qty">0)
    AND "sales_history"."sah_year"=2014
    ORDER BY "prod_warehouse"."pw_bin_location1", "prod_warehouse"."pw_prod_id"

    Try this:
    SELECT
    prod_warehouse.pw_whs_id,
    prod_warehouse.pw_prodline_id,
    prod_warehouse.pw_prod_id,
    prod_warehouse.pw_bin_location1,
    prod_warehouse.pw_min_onhand_qty,
    prod_warehouse.pw_max_onhand_qty,
    prod_warehouse.pw_onhand_qty,
    product_lookup.prlkp_lang1_1_desc,
    prod_customer.prcu_cust_part_num,
    contract_details.cond_level1_amt,
    sales_history.sah_year
    FROM sisl_data05.dbo.products products
      LEFT OUTER  JOIN sisl_data05.dbo.prod_warehouse prod_warehouse
        ON products.pr_prod_id=prod_warehouse.pw_prod_id
        AND products.pr_prodline_id=prod_warehouse.pw_prodline_id
      LEFT OUTER JOIN sisl_data05.dbo.product_lookup product_lookup
        ON products.pr_prod_id=product_lookup.prlkp_prod_id)
        AND products.pr_prodline_id=product_lookup.prlkp_prodline_id
      LEFT OUTER JOIN sisl_data05.dbo.prod_customer prod_customer
        ON products.pr_prod_id=prod_customer.prcu_prod_id
        AND products.pr_prodline_id=prod_customer.prcu_prodline_id
      LEFT OUTER JOIN sisl_data05.dbo.contract_details contract_details
        ON prod_warehouse.pw_prod_id=contract_details.cond_prod_id
      LEFT OUTER JOIN sisl_data05.dbo.sales_history sales_history
        ON prod_warehouse.pw_whs_id=sales_history.sah_sortkey1
        AND prod_warehouse.pw_prod_id=sales_history.sah_sortkey2
        AND prod_warehouse.pw_prodline_id=sales_history.sah_sortkey3
        AND sales_history.sah_year = 2014
    WHERE prod_warehouse.pw_whs_id='20123'
      AND (prod_warehouse.pw_onhand_qty<>0
        OR prod_warehouse.pw_bin_location1<>'  '
        OR prod_warehouse.pw_max_onhand_qty>0)
    Take a look at what I've done with the last line of the last join.  The issue is that when you left join to a table and you use that table in the Where clause, you've basically turned your you left outer join into an inner join because the record has to be there in order to get the value in the filter.  By moving the filter into the join, you'll still get the rest of the data when there is no corresponding record.
    NOTE:  Crystal adds all sorts of "extra" stuff like quotes and parentheses that you don't need and which I have removed to make the query easier to read.
    -Dell

  • OBIEE - Null Value in Joins

    Hi All,
    In OBIEE, How will I handle the null value in join conditions?
    I have 2 tables inner joined together in the RPD level. They are User_Profiles table and Parties table.
    I am creating a database prompt for a report and in dropdown sql results Iam giving the below query.
    SELECT distinct CASE WHEN USER_PROFILES.PAR_ID IS NULL THEN PARTIES.PAR_ID ELSE
    USER_PROFILES.PAR_ID END FROM user_profiles,parties WHERE USER_PROFILES.USER_ID='12345' AND parties.par_type = 'ABC' and parties.status = 'N'
    Here the PAR_ID is not fetched in the dropdown from PARTIES table . The reason behind this is, when the USER_PROFILES is having PAR_ID as null, it is not able to join with PARTIES table and the dropdown is not populating. It works fine when it fetch from user_profiles table. I believe the issue occurs because of the user_profiles table having null values and not able to fetch from parties table.
    Please advice..

    Hi All,
    I managed to write the query modified like below to handle the null value.
    select nvl2(user_profiles.par_id,user_profiles.par_id,parties.par_id) from WFMT_SAINT_PR where user_profiles.user_id= {User()}
    and ((user_profiles.par_id is not null and parties.par_id = user_profiles.par_id) OR (user_profiles.par_id is null and parties.par_type = 'MFR' and parties.status='C'))
    But when i put this is dashboard prompt sql results for PAR_ID field i get the following error.
    Error Generating Drop Down Values
    Odbc driver returned an error (SQLExecDirectW).
    Error Details
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 27002] Near <(>: Syntax error [nQSError: 26012] . (HY000)
    SQL Issued: select nvl2(user_profiles.par_id,user_profiles.par_id,parties.par_id) from WFMT_SAINT_PR where user_profiles.user_id= {User()} and ((user_profiles.par_id is not null and parties.par_id = user_profiles.par_id) OR (user_profiles.par_id is null and parties.par_type = 'MFR' and parties.status='C'))
    Can you please advice what is wrong here..

  • Left outer join VS Is NULL .. Please help me to understand this.

    Hi Experts,
    I have a requirement to use Leftouter join on a column. But unfortunately i couldnt implement this in OBIEE. so instead iam using = and is NULL condition. kindly help me to understand this or give me a solution.
    Advance Thanks
    I am pasting the query here. look at the last line of the query there i want to modify.
    select Targ.organization_id,Targ.cycle_count_header_name,Targ.cycle_count_header_id,Targ.cc_class_name
    ,Targ.total_cycle_count_per_month,NVL(Act.Actual_count,0)actual_count,targ.month_year,Act.count_stat,targ.year count_date_current,length(act.count_status) count_status,nvl(length(act.count_status),0)
    from
    (select
      Dim_date.Year,
    Dim_date.month_year,
    target.organization_id,
                             target.cycle_count_header_name,
                             target.cycle_count_header_id,
                             target.abc_class_id,
                             target.CC_class_name,
                            target.inventory_item_id_count,
                          target.cycle_count_per_year,
                            target.total_cycle_count_per_year,
                  target.total_cycle_count_per_month                       
    from
    (SELECT DISTINCT
                   TO_NUMBER (TO_CHAR (count_date_current, 'yyyy'), '9999') Year,
                    TO_CHAR (count_date_current, 'MON-YYYY') month_year
              FROM mtl_cycle_count_entries_v)Dim_date,
    (SELECT mth.organization_id,
                             mth.cycle_count_header_name,
                             mth.cycle_count_header_id,
                             mtc.abc_class_id,
                             mtc.CC_class_name,
                             COUNT (mti.inventory_item_id) inventory_item_id_count,
                             MIN (mtc.num_counts_per_year) cycle_count_per_year,
                             COUNT (mti.inventory_item_id)
                             * MIN (mtc.num_counts_per_year)
                                total_cycle_count_per_year,
                             ROUND (
                                (COUNT (mti.inventory_item_id)
                                 * MIN (mtc.num_counts_per_year))
                                / 12)
                                total_cycle_count_per_month,
                                TO_NUMBER (TO_CHAR (mth.creation_date, 'yyyy'), '9999') Year
                        FROM mtl_cycle_count_headers_v mth,
                             mtl_cycle_count_items_v mti,
                             mtl_cycle_count_classes_v mtc
                       WHERE mth.cycle_count_header_id = mti.cycle_count_header_id
                             AND mth.cycle_count_header_id = mtc.cycle_count_header_id
                             AND mth.organization_id = mtc.organization_id
                             AND mtc.abc_class_id = mti.abc_class_id
                              GROUP BY mth.organization_id,
                             mth.cycle_count_header_id,
                             mth.cycle_count_header_name,
                             mtc.abc_class_id,
                             mtc.CC_class_name,
                             TO_NUMBER (TO_CHAR (mth.creation_date, 'yyyy'), '9999')
                             ) Target
                                    where dim_date.Year=Target.Year) Targ,
                                  (SELECT --TRUNC (count_date_current) count_date_current,
                             TO_CHAR (count_date_current, 'MON-YYYY') Month_year,
                             abc_class_name,
                             count_status count_stat,
                             organization_id,
                             cycle_count_header_id,
                             count_status,
                             SUM (NUMBER_OF_COUNTS) Actual_count
                        FROM MTL_CYCLE_COUNT_ENTRIES_V
                    GROUP BY organization_id,
                             --TRUNC (count_date_current),
                             cycle_count_header_id,
                             TO_CHAR (count_date_current, 'MON-YYYY'),
                             abc_class_name,
                             count_status)Act
                           WHERE act.cycle_count_header_id(+) = targ.cycle_count_header_id
                   AND act.organization_id(+) = targ.organization_id
                   AND act.abc_class_name(+) = targ.cc_class_name
                    AND act.Month_year(+)=targ.month_year
                    AND targ.organization_id=254
                            AND targ.Cycle_count_header_id=3026
                             AND targ.CC_CLASS_NAME= 'A PARTS'
                             and act.count_status (+)='Rejected'I need to replace the final line act.count_status(+)='Rejected' with
    (act.count_status='Rejected' and act.count_status is NULL)But i am getting difference in data. what might be the reason?.. I am a naive user to oracle. Kindly help me and any help will be appreciated.
    Thanks alot.

    Data set for both i am enclosing here. Kindly have a look in to that.
    254     OPSCAST0909     3026     A PARTS     7     1     Dec-09     Rejected     2009                    
    254     OPSCAST0909     3026     A PARTS     7     0     Feb-09          2009                    
    254     OPSCAST0909     3026     A PARTS     7     0     Sep-09          2009                    
    254     OPSCAST0909     3026     A PARTS     7     0     Jul-09          2009                    
    254     OPSCAST0909     3026     A PARTS     7     0     May-09          2009          Data Set for outer join          
    254     OPSCAST0909     3026     A PARTS     7     0     Oct-09          2009                    
    254     OPSCAST0909     3026     A PARTS     7     0     Jun-09          2009                    
    254     OPSCAST0909     3026     A PARTS     7     0     Jan-09          2009                    
    254     OPSCAST0909     3026     A PARTS     7     0     Nov-09          2009                    
    254     OPSCAST0909     3026     A PARTS     7     0     Apr-09          2009                    
    254     OPSCAST0909     3026     A PARTS     7     0     Aug-09          2009                    
    254     OPSCAST0909     3026     A PARTS     7     0     Mar-09          2009                    
    254     OPSCAST0909     3026     A PARTS     7     1     Dec-09     Rejected     2009                    
    254     OPSCAST0909     3026     A PARTS     7     0     Feb-09          2009                    
    254     OPSCAST0909     3026     A PARTS     7     0     Jul-09          2009                    
    254     OPSCAST0909     3026     A PARTS     7     0     May-09          2009                    
    254     OPSCAST0909     3026     A PARTS     7     0     Jun-09          2009          Data set of IS NULL          
    254     OPSCAST0909     3026     A PARTS     7     0     Jan-09          2009                    
    254     OPSCAST0909     3026     A PARTS     7     0     Apr-09          2009                    
    254     OPSCAST0909     3026     A PARTS     7     0     Aug-09          2009                    
    254     OPSCAST0909     3026     A PARTS     7     0     Mar-09          2009                    

  • SCORE(n) returning zero values in an outer join query

    Hello all,
    Is there any way to get a query that contains an outer join to return proper scores. I couldn't find out why this was happening in my query, but I'm getting a score values of 0 on most results.
    Below are queries with result sets. As you can see the results that are scoring in the second query are scoring correctly, but only two have scores.
    - - - Query 1, no outer join - - -
    SELECT DISTINCT SCORE(0) AS scr,
    file_repository.file_id,
    file_repository.file_title
    FROM file_repository
    WHERE CONTAINS(index_url,'SYN(dui,a_thesaurus)', 0) > 0
    ORDER BY scr ASC
    SCR FILE_ID FILE_TITLE
    7 136 Prisoners
    7 240 Drug booklet
    8 64 Communications
    8 146 Rates
    8 168 Vehicle Collisions
    8 206 document4
    14 207 document5
    14 211 document5
    15 74 Diplomatic Personnel
    22 214 documentB
    30 81 DUI and PCA Offences
    - - - Query 2, with outer join - - -
    SELECT DISTINCT SCORE(0) AS scr,
    file_repository.file_id,
    file_repository.file_title
    FROM file_repository, file_security
    WHERE CONTAINS(index_url,'SYN(dui,a_thesaurus)', 0) > 0
    AND file_repository.file_id = file_security.file_id(+)
    AND file_security.auth_id = 0
    ORDER BY scr asc
    SCR FILE_ID FILE_TITLE
    0 74 Diplomatic Personnel
    0 81 DUI and PCA Offences
    0 136 Prisoners
    0 146 Rates
    0 168 Vehicle Collisions
    0 206 document4
    0 207 document5
    0 214 documentB
    0 240 Drug booklet
    8 64 Communications
    14 211 document5
    This is on Oracle 9i using Oracle Text.
    Thanks in advance

    To do this wouldn't you need to know the data in advance? The real source table had 1800 organisations and 8,000,000 transactions.
    I Tried this as well, creating a pl/sql package as follows.
    create or replace PACKAGE stack AS
    TYPE gnt_push_numbers IS TABLE OF NUMBER INDEX BY PLS_INTEGER;
    TYPE gvt_push_varchars IS TABLE OF VARCHAR(1000) INDEX BY PLS_INTEGER;
    gna_push_numbers gnt_push_numbers;
    gva_push_varchars gvt_push_varchars;
    FUNCTION PUSH ( pn_push_var NUMBER, pn_offset NUMBER) RETURN NUMBER DETERMINISTIC;
    FUNCTION PUSH ( pv_push_var VARCHAR, pn_offset NUMBER) RETURN VARCHAR DETERMINISTIC;
    FUNCTION POP_NUM ( pn_offset NUMBER) RETURN NUMBER DETERMINISTIC;
    FUNCTION POP_VAR ( pn_offset NUMBER) RETURN VARCHAR DETERMINISTIC;
    END stack;
    CREATE OR REPLACE
    PACKAGE BODY "STACK" AS
    FUNCTION push(pn_push_var NUMBER, pn_offset NUMBER) RETURN NUMBER deterministic IS
    BEGIN
    gna_push_numbers(pn_offset) := pn_push_var;
    RETURN pn_push_var;
    END push;
    FUNCTION push(pv_push_var VARCHAR, pn_offset NUMBER) RETURN VARCHAR deterministic IS
    BEGIN
    gva_push_varchars(pn_offset) := pv_push_var;
    RETURN pv_push_var;
    END push;
    FUNCTION pop_num(pn_offset NUMBER) RETURN NUMBER deterministic IS
    BEGIN
    RETURN gna_push_numbers(pn_offset);
    END pop_num;
    FUNCTION pop_var(pn_offset NUMBER) RETURN VARCHAR deterministic IS
    BEGIN
    RETURN gva_push_varchars(pn_offset);
    END pop_var;
    END stack;
    Unfortunately it appears to act before the rows are sorted, so will only work in specialised circumstances, in that you have to ensure the rows have been sorted before the function is used.
    SELECT PUSH(COL), POP..(COL)
    FROM ( SELECT etc.
    Luckily the client decided they didn't want to mix their graphs any more so a more classic approach using a base table select for actuals and then a date table select with a sub-query columns for the projection provided a simple solution.

  • What is IS NULL doing in replacing NOT EXISTS operator with an outer join?

    DB version:10gR2
    An example from searchoracle.target.com
    The query which contains a NOT EXISTS operator
    SELECT M.ModulId, M.Modul FROM MODULE M
    WHERE NOT EXISTS
    ( SELECT PROJEKTMODUL.IdModul
      FROM PROJEKTMODUL
      WHERE M.ModulId = PROJEKTMODUL.IdModul
      AND PROJEKTMODUL.IdProjekt = 23 )is replaced by an equivalent outer join query
    select distinct
           M.ModulId
         , M.Modul
      from MODULE M
    left outer
      join PROJEKTMODUL
        on M.ModulId = PROJEKTMODUL.IdModul
       and PROJEKTMODUL.IdProjekt = 23
    where PROJEKTMODUL.IdProjekt is nullI don't understand what
    PROJEKTMODUL.IdProjekt is nullis doing in the above rewritten query.

    It is to perform an Anti-Join. As far as I know Oracle (starting with release 10g - I thought Release 1) rewrites your NOT EXISTS and NOT IN query to a Anti Join which looks like your second query.
    Look at the results of the query without the IS NULL predicate and see which records (from that set) should be selected to show the same results as the first query. The records of interest match the predicate IS NULL.

  • Left Outer Join & IS NULL Not Working

    In a Data Flow Query element I am using a Left Outer Join to correlate two tables. In order to eliminate rows in which the Left Outer Join found a match with the Right table I am using IS NULL in the Where clause. Unfortunately IS NULL doesn't seem to return true when the NULL is caused by a lack of a match on a Left Outer Join. Has anybody been able to work around this?

    Use not is NULL in next query after the join.
    A source 1 ---
                           C (join query) ----- D (filter condition IS NULL)
    B source 2 ---

  • Joining 3 tables with null values

    Hi,
    I have three tables that have varying data in. I want to write a query which will list all three in the result set, but when one of the tables doesn't have a row, write in No Value.
    I will be intending on joining the tables with account numbers. What will be the syntax of a join with three tables where I am not sure which table will have null values?
    Thanks...

    Something like
    select nvl(a.id,'No Value'), nvl(b.id, 'No Value'), nvl(C.id, 'No Value')
       from (select id from t1) a,
                  (select id from t2) b,
                  (select id from t3) c
      where a.id = b.id(+)
          and a.id = c.id(+)
    Hi,
    I have three tables that have varying data in. I want to write a query which will list all three in the result set, but when one of the tables doesn't have a row, write in No Value.
    I will be intending on joining the tables with account numbers. What will be the syntax of a join with three tables where I am not sure which table will have null values?
    Thanks...

Maybe you are looking for

  • IMac Tech Specs vs. PC's

    I'm a PC user thinking of buying an iMac. Does iMac require less memory and hard drive space than PC? The standard specs. for an iMac is 1GB memory and 250 GB HD. If it were a PC I would consider 2GB/320GB the standard (for me anyway). I realize that

  • '&' character and BI Publisher Intergration

    Just wanted to post this for others when they start using BI Publisher and APEX.. I have a number of reports in APEX that we are using BI Publisher to produce printed output. In one of the reports I had a & in the region title in APEX. When BI Publis

  • Skype for Business Client update

    Hi, First of all let me get this out of the way "Microsoft Office 365 support sucks". now the simple question: If office proplus is installed via portal (through on-click run), how does it get the update for skype for business? I have over 1000 users

  • Depreciation Run for closed fiscal year

    Hi All, We bought some assets on 2005 through direct purchase and these assets are in under operation, but not having the asset master record in the SAP system. Now we have decided to bring these assets into the system as the capitalised date is 10 N

  • Migratind ADFS 2 to ADFS 3

    Hi Guys we are looking into migrating our ADFS 2.0 to 3.0 One of our major concern is downtime as most of our infrastructure relies on this Server Role to authenticate. we would like to know if it's possible to run ADFS 2.0 and ADFS 3.0 simultaneousl