Joins on different fields based on a condition

Hi,
I have 2 tables, each consists of 5 fields, based on Field3's data, I want to join either F1 & F2 or F4 & F5.
I have given below the field creation and sample data for your reference. When I run the SQL with "case when .."
statement, it gives "ORA-00905: missing keyword" error.
I can do this by splitting into 2 separate SQL statements one for F1 & F2 and the other for F4 and F5.
Is there any other better way of doing it in a single SELECT statement?
Please share your views, thank you.
create table tmp_a
(f1 varchar2(50),
f2 varchar2(50),
f3 char(1),
f4 varchar2(50),
f5 varchar2(50))
create table tmp_b
(f1 varchar2(50),
f2 varchar2(50),
f3 char(1),
f4 varchar2(50),
f5 varchar2(50))
begin
     insert into tmp_a
     values('R1', 'abc', 'L', 'A1', 'B1');
     insert into tmp_a
     values('R2', 'lkj', 'L', 'A2', 'B2');
     insert into tmp_a
     values('R3', 'qwe', 'M', 'A3', 'B3');
     insert into tmp_a
     values('R4', '123', 'M', 'A4', 'B4');
     insert into tmp_b
     values('R3', 'qwe', 'L', 'A1', 'B1');
     insert into tmp_b
     values('R2', 'lkj', 'L', 'A2', 'B2');
     insert into tmp_b
     values('R4', '123', 'M', 'A3', 'B3');
     insert into tmp_b
     values('R1', 'abc', 'M', 'A3', 'B3');
     commit;
end;
select * from tmp_a;
select * from tmp_b;
select a.*, b.*
from tmp_a a, tmp_b b
where a.f1 = b.f1 and a.f2 = b.f2;
select a.*, b.*
from tmp_a a, tmp_b b
where a.f4 = b.f4 and a.f5 = b.f5;
select a.*, b.*
from tmp_a a, tmp_b b
where case when a.f3 = 'L' then
          a.f4 = b.f4 and a.f5 = b.f5
     else
          a.f1 = b.f1 and a.f2 = b.f2
end;

Maybe something like:
SQL> SELECT a.*, b.*
  2    FROM tmp_a a, tmp_b b
  3   WHERE CASE
  4            WHEN a.f3 = 'L'
  5               THEN a.f4
  6            ELSE a.f1
  7         END = CASE
  8                 WHEN a.f3 = 'L'
  9                    THEN b.f4
10                 ELSE b.f1
11              END
12     AND CASE
13            WHEN a.f3 = 'L'
14               THEN a.f5
15            ELSE a.f2
16         END = CASE
17                 WHEN a.f3 = 'L'
18                    THEN b.f5
19                 ELSE b.f2
20              END
21  /
F1         F2         F F4         F5         F1         F2         F F4         F5
R1         abc        L A1         B1         R3         qwe        L A1         B1
R2         lkj        L A2         B2         R2         lkj        L A2         B2
R3         qwe        M A3         B3         R3         qwe        L A1         B1
R4         123        M A4         B4         R4         123        M A3         B3
4 rows selected.Regards,
Jo
Edited by: Joice John on Jul 17, 2009 4:30 AM
Sigh!!! Sean you are too fast for me.... ;)

Similar Messages

  • Unable to filter a formula field based on two conditions

    hi,
    I have a report with 3 subreports in it. When i drill down onto first subreport i am getting correct records in details based on selection criteria but when i am unable to populate the same record count in summary.
    For example
    On summary i see : 60 when i drill down i see 20 records which is correct but not reflecting onto summary report
    the details selection criteria is based on two  fields where field1>=1 and field2= "Text"It is coming out good (20 records) but in summary i am unable to populate this based on same selection criteria
    The main issue i am facing was if i apply a filter on summary selection criteria all the subreport counts are getting affected. Is there a way i can apply filters only one one field
    Please suggest
    Thanks!
    Lucky

    Thanks! for the prompt response Abhilash
    I got part of what you told me. Yes i am calculating the counts in the summary report.
    Basically here is the selection criteria: i need to filter the records based on two conditions. One is x.field1= "Admin" and x.field2=act_pct>=1
    For example:
    Admin Returns         50  but when i dig into details it showing as 20 records ( based on selection criteira above)
    when coming back to summary . 50 what ever is returing here is based on a formula ( if x.field1="admin" then 1 else 0) ..in addition to this i need to filter that by x.field2>=1 which is not taking it     
    Is there any syntax to do this
    If i apply a filter on this particular 50 record its bee applying for whole summary report ...
    And from what you said :
    Why don't you create the summary in the Subreport and maybe use shared variables to bring it back to the Main Report?
    i did not get this
    Please suggest
    Lucky

  • Dynamic Action - How to enable  text field based on a condition

    Hi,
    I have two text items. Need to create dynamic action for the following,
    1. Order_type - Drop down values having CONSUMER & WHOLESALE.
    2. Order_number- Text field
    Order number should be disabled and only on selection of order type ,order number should be enabled.
    Can someone please help me on this?

    Hi Gayathri,
    Gayathri Venugopal wrote:
    Hi,
    I have two text items. Need to create dynamic action for the following,
    1. Order_type - Drop down values having CONSUMER & WHOLESALE.
    2. Order_number- Text field
    Order number should be disabled and only on selection of order type ,order number should be enabled.
    Can someone please help me on this?
    Create two dynamic action
    1. Make it order number item disable on page load.
       Event : Page Load
       Action : Disable
       Fire When event result is : True
       Selection Type : Item
       Item : Your order number item
    2 . enable and disable order number on selection of order type(assuming when order type is null it is disable otherwise it is enable)
        Event : Change
        Selection type : item
        Item : your order type item
        condition : is not null
    True Action
        Action : Enable
        Fire When event result is : True
        Fire on page load : True
        Selection Type : Item
        Item : Your order number item
    False Action
        Action : Disable
        Fire When event result is : False
        Fire on page load : True
        Selection Type : Item
        Item : Your order number item
    Hope this helps you,
    Regards,
    Jitendra

  • Different receivers based on a condition

    Hello experts,
    I have a scenario File to IDOC . The file has the structure : Many transactions( codes starting from 111 to 999)and one Footer record. The footer record will have the total number of lines, and the total number of 111 codes .
    The file has to be read by XI and if the total number of lines or the total number of 111 trasactions does not match with that of the numbers in the footer record, then an email has to be sent to a distribution list (external partners) saying that the bumner of lines or the number of 111 trnsactions do not match with that of the numbers mentioned in the footer record.
    If the numbers match , then the file has to be mapped to idoc .
    This is kind of one file to multple receivers but not exactly multiple recievers, of the mail adapter s triggered, then the idoc adapter should not be triggered.
    I tried it with multimapping: 1 message for Mail and the other for IDOC, and tried giving the condition createif  for mail node but it is throws out error:
    Cannot produce target element /ns0:Messages/ns0:Message1/ns2:Mail.
    Can you please help me in acheiving this scenario.
    thank you.

    Hello all,
    thank you for your replies.
    I have tried the option of enhanced receiver determination.
    There is no need of multimapping. Here are the steps that i followed to achieve the required result:
    Used the Receviver determination as my message interface  and in the mapping of the Server,
    the Message type -->Receivers -->http://sap.com/xi/XI/System
    the Message Interface --> ReceiverDetermination -->http://sap.com/xi/XI/System of swcv SAP BASIS 7.00
    I have given the condition for the Receiver Services for the Field Service.
    and in the configuration part there is no change in the usual Sender agreements, Recevier agreemants and Interface determinations. But in the receiver determination , i have selected the Enhanced radio button and selected the interface mapping for the receiver determiantion .
    This works.
    Regards,
    Lakshmi.

  • 'Join' two different field types together into a String - possible in Java?

    Not entirely certain whether this is a straightforward Java or more of a JDBC question:
    I have two fields, one is a String and one an integer. I need to concatenate these fields together to form one String, prior to performing an insert on a table. ie:
    String s = dbRS.getString("partition_name");    //get full string
    String partstr = s.substring(0, 14);      // get first 14 (alpha) characters
    int new_partition_number = max_partition_number + 1;      //create new unique partition number, incremented by 1Now I have
    - a String (partstr - i.e. "TN1234567890_")
    - an integer (i.e. 50)
    (NB. The number has to be an integer because it is subject to calculation elsewhere.)
    I wish to join these together into a String ("TN1234567890_50") and use the field in an inserted row. I've tried using
    String partition_string = new StringBuffer(partstr).append(new_partition_number ).toString();... but this doesn't work.
    I read on a forum that it's impossible to cast an integer to a String in this way in Java, which sounds pretty incredulous from where I am! However my Osborne Java 2 Complete Reference doesn't mention it at all.
    Any assistance will be very gratefully received!
    Thanks.

    wonder why he thinks you can't append an int to a StringBuilder.
    Works fine. Might of course not yield the expected result depending on expectations, but it works just fine.
    But then, the coding conventions reminiscent of C don't bode well.

  • Selecting a value to a column from a different table based on a condition

    I apologize for the confusing title.
    I have to select values from Table_1. 2 of those columns needs to be checked for values in Table_2 based on the ID and if values are present, then those values should be taken, if not the values from Table_1 should be taken. How can I achieve this?
    e.g.
    table_1
    date
    id
    fact1
    fact2
    type
    table_2
    id
    fact1
    fact2
    select date,id,type, (Need to check the condition for fact1 and fact 2, if present in table_2, then that value should be used, if not table_1 values should be used) from table_1 and table_2.
    I need to use this condition in another big query. Any help/suggestions appreciated.
    Thanks.

    Thanks Tubby,
    It worked and I incorporated with the master query too.
    Thanks a lot.
    EDIT
    Thanks for all the replies> I just saw your answers after I finished and posted the reply.
    hoek, I am not a DB person, I used to write some SQLs, but not in the last 3 years or so. I am trying to work on some reports, hence some trivial questions.
    Edited by: vj on Aug 7, 2010 5:48 PM

  • Hiding a caption and field based on context condition

    Hi,
    I have what should be a simple problem, but I'm not sure if what I'm doing is the correct way to solve it.
    I have a telephone number of a user master being output, and if there is an extension number I want to output that as well, separated by ext
    In the context node I have put a condition on the Extension field (GS_HEADER-FSABE-TEL_EXTENS1 not equals INITIAL), and debugging the code of the function module shows that %OUTPUT is not being called for the Extension field in the layout as expected.
    The Extension field in the layout is bound to the Extension field in the context, and the caption is set as "Ext"
    Therefore I either want to output
    Telephone: 01234 567890 ext 1234
    or
    Telephone: 01234 567890
    It's not working though, as I still get ext printing even when there is no Extension - have I done something wrong or is this not the correct way to go about this?
    Thanks,
    Vindaloo

    Thanks very much, this has solved the problem
    In the layout:ready event for the extension field I have put the following Javascript:
    // Hide the Telephone Extension caption & value if it is not populated
    if (this.rawValue == null) {
      this.presence = "hidden";
    I was under the misapprehension that simply putting a condition onto the field in the context would stop it being passed to the form and rendered.
    The layout:ready event seems to be the best place to put this code.  However, the adobe help for this event is confusing as it contains the following:
    Initiates after the form design and data are merged, the form exists, and the form's layout is applied. At this time, the finished form has not been rendered; therefore, a calculation or script set to run on this event could modify the layout before the form is rendered.
    This is fine and fits in with what I have.  It then goes on to say:
    Note: Scripts that fire on layout:ready should not do anything that would cause the layout of the form to change. For example, this would include anything involving subforms or tables that grow or shrink, adding fragments dynamically at run time, adding or removing subform instances, and toggling the presence setting of an object between hidden and visible.
    This seems to be in direct conflict with the previous statement, regarding modifying the layout.
    Vindaloo

  • WriteBack: Update a field based on two conditions.

    Hi Experts,
    I am facing a serious problem in write back to database.
    Let me explain the writeback i am trying to do.
    I have a table as Below
    Col1----- Col2---------Col3----------Col4
    100--------1-------------2----------100/(1+2)
    Col1,col2,col3 are editable.
    Once the values are entered in these columns Col4 is calculated by the formula (Col1/(Col2+Co3))
    If the user enters 0 in col2 and col3 then it will be a division by zero which i have handled by the DECODE function
    But the user requires a standard value to be shown there that is Col1/0.57895 whenever he enters 0 in col2 and col3.
    I initiially put a column formula for Col4 in answers saying if col2 or col3 = 0 then (Col1/0.57895)
    But as this formula is only at the prsentation level...teh values were not getting saved in the database.
    My requirement is i need to put this condition in the writeback xml itself and see to it that this standard value be updated in the table itself.
    like
    update table set col4=Col1/0.57895 where col2=0 and col3=0
    Update table set col4=(Col1/(Col2+Co3)) where col2 <>0 or col3<>0
    I am unable to use two update queries in teh xml template.
    Please let me know how can i implement this in the xml template.
    Appreciate your immediate response.
    -Best Regards!

    You can't do it in the xml but you can do it in the database with a before trigger update
    http://www.techonthenet.com/oracle/triggers/before_update.php

  • Print Adobe form pages on different printers based on the condition

    Hi All,
    I am new in Adobe forms. We have requirement to print first 5 line items in adobe form (which are printing on first page) on one printer and remaining pages on another printer.
    What solution I was thinking was, in print program call the adobe form twice with flag as a importing parameter. For the first call the flag value will be set and for second run a blank value will be passed in flag.
    If flag is set then call make the first page "visible" and if flag is cleared then "hide" the first page and make the remaining pages "visible".
    But as its an item data which is designed on "Design" view I am not able to write a script to hide the page. Any suggestion you can give to resolve this issue.
    Thanks,
    Mihika.

    If it is OK to have the default printer defined/maintained in the user master (like tcode Su01 or System > User profile > Own data, Then the standard logic may suit your needs. I think you will need to undo some config for the whs. Te standard logic works as detailed below. the system needs to get to #4 below, then the SAP userid printer will be selected.
    the system proceeds with automatic printer determination as described below Config Tcode is OMLV.
    1) First the system checks whether a printer is set in the configuration "Printer-Movement". If so, the printer determination is complete at  this point.                                                         
    2) If not, the system uses the parameter "PriSrcTyp" defined in the configuration "Printer-Movement" to decide how it will proceed.  If the parameter is set here, the system checks if a printer is defined in the setting "Printer Picking Area" and then proposes this printer.                                                            
    3) If the system finds no printer, it searches in the setting "Printer - Storage Type" and uses this, if a printer is set.                   
    4) If the system cannot find a printer using the methods described above it selects the printer defined in the user master of the user currently logged on.                                                
    5) If no printer is defined here, the system automatically proposes LP01
    This writes the data to the spool file.

  • How to count number  of records for a field based on condition?

    Hi guys,
    I want to know how to find count of records coming from the database for a particular field based on some condition.
    I need to use this count to suppress some headers. Because of this i am not able to use running totals. Is there any other way?
    Ex scenario:
    I have account number and currency fields, those are coming from database. And i need to count the number of accounts whose currency is not Euro.
    Thanks in advance,
    Vijay.

    A simple formula can do that:
    //Formula begin
    if {your account field}<>"Euro" then 1
    //Formula end
    This formula can be summarized. (by group or report)
    Bryan Tsou@Taiwan

  • Setting a field as Mandatory dynamically based on certain condition

    Hi All -
    I am working on ADOBE Interactive forms. I am not able to find out, How to set a particular field as a 'Mandatory field' based on some condition. I am using FormCalc as scripting language.
    i.e: I have a field "RATING". I want to make the next field "COMMENT" as mandatory when "RATING" is less than 3.

    Hi Vishal,
       You need to set the mandatory attribute of the specific field according to your condition. In FormCalc this will be similar to this,
    if (Rating < 3) then
              $.mandatory = "error"
              $.mandatoryMessage = "The corresponding Comment field is mandatory. Please fill"
    else
              $.mandatory = "disabled"
    endif
    The mandatory property can be set as:
    "error" : Makes the field compulsory to be filled before submission
    "disabled" : Makes the field optional
    "warning" : Gives a warning to the user that the field should be filled, but doesn't cause an error on submission
    The property "mandatoryMessage" specifies the message to be displayed to the user when the mandatory field isn't filled before submission.
    Regards,
    Rose

  • How to store the AccountID of a user in a field based on selection of name in a different dropdown

    When our form is first loaded we store the current users name in the "username" field.
    I have a “VPApprover” drop down field which is doing a look-up to a secondary list where we have two columns, Approver Name and Department. The Name column is a person column and I currently have the “username” displayed in the view
    When a user is creating a new request they need to select a VP Approver
    What I want to do is when the user selects an Approver,  store the Approvers “username” aka "AccountID" from the secondary list in the vpusername field on the form. Then on future editing of the form, I’ll compare the “username” field to the
    “vpusername” field and if they are the same display an “Approve/Deny” drop-down.
    I've tried selecting different Fields from the Approver secondary list, but can't seem to get the field on the form to update correctly based on the drop-down selection.  I have a rule set on the Drop-down field to set the vpusername field.. The Condition
    is currently “If vpApprov is not blank” ..
    When I get to the Value part, I can't figure out how to "grab" the AccountID of the VP Approver selected and store it in the field on the form. The fields I see in the secondary list under person are "DisplayName", "AccountID",
    and "AccountType".
    Thanks in advance for any help you can give me!!
    Shane Meisner
    SharePoint Solutions Architect

    Hi,
    From your description, my understanding is that you want to store account id to a filed based on a lookup column.
    You could accomplish your requirement with Workflow, you could create your workflow with these steps below:
    Create a local variables.
    Use Set Workflow Variable action to set value to the variable.
    Use Set Field in Current Item action to set value to the column(Please refer to the screenshot below).
    And the screenshot below is the list15 and result in my environment.
    Best Regards,
    Vincent Han
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • How to creat a Data provider  based on different fields in SAP BW ?

    Hi,
    Experts,
    There are  20 fields  of  Plant Maintainace  like : 
    SWERK
    BEBER
    STORT
    TPLNR
    EQUNR
    INGRP
    QMDAT   ---peroid
    STTXT
    QMDAT  - Date of Notification
    QMNUM
    QMTXT
    QMART
    AUSVN
    AUZTV
    AUSBS
    AUZTB
    AUSZT
    ERNAM
    QMDAB
    AUFNR
    I  want to creat a  Report based upon these fields  ?
    For that I h'v  checked the relevant Fields to the   existing standard  Datasource  in Bw side   &
    Checked  cubes   created  based upon these Datasource  in Bw side !
    i h'v found  some fields are  existing different cubes & some are  missing .
    How to creat a Data provider  based on different fields in SAP BW ?
    plz suggest      !!!!!!!
    Thanx,
    Asit
    Edited by: ASIT_SAP on Jul 15, 2011 6:25 AM
    Edited by: ASIT_SAP on Jul 15, 2011 6:27 AM
    Edited by: ASIT_SAP on Jul 15, 2011 12:37 PM

    Hi Lee, Please see below..
    DECLARE @Machine2 TABLE
    DispatchDate DATE
    INSERT INTO @Machine2 VALUES ('2014/02/01'), ('2014/02/02'), ('2014/02/03')
    DECLARE @DateFrom DATE
    SELECT @DateFrom = DATEADD(D,1,MAX(DispatchDate)) FROM @Machine2
    SELECT @DateFrom AS DateFrom
    Please mark as answer, if this has helped you solve the issue.
    Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.

  • Mailing from XI to different groups based on Condition

    Hi Experts,
    I have a scenario where i have an incoming XML Invoice document which i need to map with Invoic02 idoc and to send to R/3.
    While sending it to R/3 i also need to put conditions on certain special links,when fails sends out mails to a
    respective mail group .
    When i get a wrong field/condition the map fails.Based on the condition which failed the map,XI should be mailing to
    the respective group .
    I will be having around 4-5 mailing groups in the single map .
    Please suggest me some helpful blogs and inputs for this scenario.
    Thanks,
    Sudhansu

    B'cos you are failgn the mapping at deisgn time (by various conditions), you can configure diff ALERTCategories & invoke them appropriately from your UDF.
    /people/bhavesh.kantilal/blog/2006/07/25/triggering-xi-alerts-from-a-user-defined-function
    For each of these AlertCategories, you will configure your respective recepients.
    Regards,
    siva Maranani

  • Adding few fields to the ODS based on a condition

    Need suggestions in adding few fields to the ODS based on a condition.
    The following is the requirement.
    Do a calday and 'Sales Org' based selection:
    0CALDAY=20041101-99991231; All Sales Orgs except AM01
    0CALDAY=20030701-20070930; All Sales Orgs except AM01

    Hi Dolly,
                   You can do this by writing a simple end routine in your transformation rules.It is just an  conditional statement.
    In that statement write
    If <RESULT_FIELDS>CALDAY EQ 20041101-99991231 and If <RESULT_FIELDS>Sales Org NE AM01
    <write the statements which populate the fields>
    endif.
    In the same way you can write the code.
    Hope this helps
    Regards
    Karthik

Maybe you are looking for

  • HP 2025/XP: Error Message when printing envelopes wider than long

    Is there any way to print envelopes wider than long (e.g., A2 through A7) without getting the error message "Unrecognized Paper" and encountering long cleaning cycles between each envelope.  I prefer not to feed envelopes end-ways as they tend to gat

  • External display no longer being recognized ideapad u310 touch with Win 8.1

    Several weeks ago I was able to attach a external monitor with a HDMI to DVI cable and it has been running without any problems until today when I turned on the laptop and nothing came up on the external display. Control panel only shows one display

  • Load Image into JApplet

    Hello to all Java expect coder, i would like to load an image to an applet but after it flash once time then it just disappear. Below is my code : * SodaVendingMachineApplet.java * Created on June 8, 2008, 4:08 PM import java.awt.*; import java.awt.i

  • What is an Invoice list? Why is it used?

    Hi All, Can any one tell me what is an Invoice list? Why is it used? Thank you for your help. Regards, Shanu

  • Dynamic url link for Crystal Reports Enterprise?

    Hi all, We recently upgraded to SBOP 4.0 SP2 and are looking at migrating our existing Crystal Reports from Crystal Reports 2011 to Crystal Reports for Enterprise 4.0. Up to this point we have been utilizing the BW Publisher and role menus in BW. Our