Query for multiple row to single

Hi All,
Need help in Multiple row to single row
create table cust_tranc_track
(id number,
payment_dt date ,
emi_dt date,
appr_dt date
SET DEFINE OFF;
Insert into CUST_TRANC_TRACK
   (ID, APPR_DT)
Values
   (425, TO_DATE('11/12/2012 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into CUST_TRANC_TRACK
   (ID, PAYMENT_DT, EMI_DT)
Values
   (425, TO_DATE('11/01/2012 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('11/13/2012 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
COMMIT;
Output :
ID     PAYMENT_DT     EMI_DT              APPR_DT
425     11/1/2012     11/13/2012     11/12/2012thanks
ajr

*> g2500 wrote:**> Hi All,*
*>*
*> Need help in Multiple row to single row*
*>*
*> *
*>*
*>*
**_+Hi,+_**
**_+I cant clear about ur question. I m giving the solution wat i can understand.to get multiple row inti single u can use listagg function.+_**
**_+use hr.employees+_**
**_+select department_id,listagg(first_name,',') WITHIN GROUP (ORDER BY first_name) AS employeename+_**
**_+from employees+_**
**_+group by department_id;+_**
**_+u [http://dba-oracle.com/t_oracle_listagg_function.htm]+_**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Return Code - Query for Multiple Rows as XML

    Hi,
    I'm executing an MSSQL stored procedure through the "Query for Multiple Rows as XML" activity in LiveCycle ES. I do this through a call statement such as this:
    { call MyStoredProc(?) }
    This works great, the stored procedure always returns a record set (with or without records). I use this activity rather than "Call Stored Procedure" because I can transform the record set into XML right away within this activity. Unfortunately any exception arising from invoking this stored procedure cannot be handled within the workflow as this activity does not have an exception handler (lightning bolt). In an attempt to handle at least some exceptions we have decided to use try/catches within the stored procedures and return different error codes. Now the problem I am faced with is that there is no way to retrieve the returned code within any of the SQL activities. We don't want to have to write an execute script for each of these SQL calls. Is there any way to do this? Seems like I'm 95% there.
    Thanks
    Nic

    Thanks for the offer, unfortunately we would need something certified by Adobe.
    Nic

  • Query for Multiple Rows as XML

    Ok I've seen this topic in the forums, but have failed to get this to work within my process. Basically I have a process that has a user fill out a form, and upon submittal the form writes it's information to a database (via a data connection within the form that invokes a separate process upon submittal.), once this is done the main process is invoked and it's first step is to query that same database and bring back the data in a lower (now exposed) portion of the form that contains certain fields that track the issue history. The query brings back the xml document and I store it in an xml variable (xml_output). I then take this information and use the Set Value object to assign the returned nodes values to the location fields in the form. This works if the query returns only one row. But once the form is moved beyond the initial Task Assignment, (first user), and query returns more than just one row, the added nodes to not show up on the form, i.e I still just get information about the first row in my form. From what I've read the form should be able to recognize the xpath expression, and bring back all the nodes, by in a sense using instance manager to create an instance for each node on the form. My question is how can I get this to work. Jasmin if your still out there... Help!
    Also We're using Adobe LiveCycle ES 8.0
    created the process using Workbench
    the form was reader enabled and saved as a dynamic PDF.
    Thanks
    Mike

    Ok have done the binding of the schema to the form, and I'm getting the information to flow as it's supposed to.  The problem I'm having now, (I know I'm having a bunch.) is that once I've placed the form into my process, and I use the set value operation to pre-fill information I get the form to flow, but the rest of the information that was previously filled in is blank.  So I have checked the variable and nothing wrong there.  It appears the problem is how I'm using the set value operation.  If I don't use the set value operation, the form retains it's information.  And if I use the set value by trying to set the subform value, the form retains it's information, but no pre-fill.  I'm going to try to be a little more detailed here.  The xml that is returned looks like this:
            0016-03-30
            Mike
            Public Works
            alone in the dark
            Type sleep
            -1
            Council
            FYI
            Important
    Flowed and positioned are actual subforms on the form that have their properties set as their names indicates.  The entire path is /form1/Page1/flowed/positioned .  The way I was able to get the form to flow correctly upon the injection of this xml data, was to bind the subforms in the form in this manner, positioned[*].  Designer didn't place the [*] for me so I had to do this myself.  But once I previewed the document, the form pre-populated and created the necessary number of subforms and placed information into the fields correctly.
    Now on the process side, I have created an xfaform variable that stores the form (bound to xsd.)  information, and another xml variable that stores the query return that looks like the xml listed above (has an xsd associated with it for navigating xpath).  My first operation performs the query (JDBC- Query Multiple Rows as XML) and stores it into the xml variable.  The next step of the process is the Set Value operation which is supposed to inject the xml data retrieved from the query into the form.  Initially I tried the an xpath similar to the following:
    /process_data/object/data/form1/page1/flowed/positioned = /xml_data/flowed/positioned.
    No dice.  On this one the form retains the information filled out by the user (didn't explain this earlier, the form is filled out first, and upon submittal the process starts.), but doesn't pre-populate the bottom part of the form.  Next I tried the following xpath:
    /process_data/object/data/form1/page1/flowed = /xml_data/flowed/positioned.
    This time it retained the form information which was filed in by the user, but the bottom part is becomes hidden!  Didn't understand this.  But I started to kinda think that I had to navigate he xpath in order to correctly inject the xml into the form.  That being said my next attempt was:
    /process_data/object/data/form1/page1 = /xml_data
    My thinking was that if on location, I stop at page1, the xml in the variable will allow it to navigate correctly through the form.  Well it worked, but too well.  The top part of the form is blank, but the bottom portion is pre-populated correctly.  Now I'm stuck.  Not sure how to get the rest of the information in the form.  I thought about creating variables form each of the fields and then re-populating them after the injection of xml, but that didn't seem practical.  I'm almost positive it's something I'm not doing correctly with xpath.  Anyway, thanks for all your help on this.
    Mike

  • Query for Multiple Rows as XML 'NULL' question

    There are two fields in the database.
    Foo = null (real null)
    Foo1 = '' (blank string)
    In my return xml the nodes are as follows:
    <Foo>null</Foo>
    <Foo1/>
    Why is it that if there is a null in the database, that it puts the string null, and then when there is a blank string, the node is empty?
    How can I get the null value to act like the blank value?
    Cheers

    SELECT COALESCE(Foo,''),COALESCE(Foo1,'') FROM mytable;
    The above query will return '' (empty string) if the columns has NULL value.
    This is another solution.
    Third solution is to apply XSL and remove NULL value.

  • Convert  multiple rows into single rows for the respective index name

    Dear Experts,
                             I want to convert  multiple rows into single rows for the respective index name,
                            Here is my query.
    SELECT user_tables.table_name, user_indexes.index_name, user_ind_columns.column_name
    FROM user_tables
    JOIN user_indexes on user_indexes.table_name = user_tables.table_name
    join USER_IND_COLUMNS on USER_INDEXES.INDEX_NAME = USER_IND_COLUMNS.INDEX_NAME
    where user_indexes.index_name not like '%PK%' AND user_ind_columns.column_name NOT LIKE '%SYS%'
    ORDER BY user_tables.table_name,user_indexes.index_name;
    Result of previous query
    TABLE_NAME
    INDEX_NAME
    COLUMN_NAME
    T1
    IDX_ACCNTYPCFG1
    ENABLE_SERVICE
    T1
    IDX_ACCTTYPCFG1
    ACC_CODE
    T1
    IDX_ACCTTYPCFG1
    ACCTYPE
    T2
    IDX_ACCTTYPCFGAPP1
    ACCTYPE
    T3
    IDX_ACTLG1
    MOBILE_NO
    T3
    IDX_ACTLG1
    ID
    Desired output required is
    TABLE_NAME
    INDEX_NAME
    COLUMN_NAME
    T1
    IDX_ACCNTYPCFG1
    ENABLE_SERVICE,ACC_CODE,ACCTYPE
    T2
    IDX_ACCTTYPCFGAPP1
    ACCTYPE
    T3
    IDX_ACTLG1
    ACCTYPE,MOBILE_NO
    please help.

    Maybe
    with
    user_tables as
    (select 'T1' table_name,'IDX_ACCNTYPCFG1' index_name,'ENABLE_SERVICE' column_name from dual union all
    select 'T1','IDX_ACCTTYPCFG1','ACC_CODE' from dual union all
    select 'T1','IDX_ACCTTYPCFG1','ACCTYPE' from dual union all
    select 'T2','IDX_ACCTTYPCFGAPP1','ACCTYPE' from dual union all
    select 'T3','IDX_ACTLG1','MOBILE_NO' from dual union all
    select 'T3','IDX_ACTLG1','ID' from dual
    select table_name,
           case index_name when 'IDX_ACCNTYPCFG1' then 'IDX_ACCTTYPCFG1' else index_name end index_name,
           listagg(case column_name when 'ID' then 'ACCTYPE' else column_name end,',') within group (order by null) column_name
      from user_tables
    group by table_name,case index_name when 'IDX_ACCNTYPCFG1' then 'IDX_ACCTTYPCFG1' else index_name end
    TABLE_NAME
    INDEX_NAME
    COLUMN_NAME
    T1
    IDX_ACCTTYPCFG1
    ACCTYPE,ACC_CODE,ENABLE_SERVICE
    T2
    IDX_ACCTTYPCFGAPP1
    ACCTYPE
    T3
    IDX_ACTLG1
    ACCTYPE,MOBILE_NO
    Regards
    Etbin

  • Formula to calculate SUM of multiple sheets of excel and the result to be stored in another excel sheet and pop up alerts for multiple rows

    I have a excel with multiple
         sheets with data as shown below
    SHEET 1
    A 1
    B 2
    C 3
    SHEET 2
    B 1
    C 2
    A 3
    SHEET 3
    C 1
    A 2
    B 3
    My
    query is splitted into 3 categories
    I want to have a formula to do math calculation such that data of "A" of SHEET 1 is  calculated with "A" of SHEET2 irrespective of the location of "A".
    When I include SHEET3, the formula should automatically identify the location of "A" or "B" or "C" and give the result corresponding to A, B or C. Since I want to bifurcate daily report and output printed. I want to use another
    excel for output. How to link multiple sheets of one excel and print the output of above in
         another excel?
    Assume, I have 4 SHEETS,  "SHEET 1", "SHEET 2", "SHEET 3" and "SHEET 4". Math calculation need to be done using all 4 sheets. If
    I include "SHEET 5", the formula should ignore SHEET 1  automatically and give the results of SHEETS 2 to 5. Similarly, if I include SHEET 6, SHEET 1 and 2 need to be ignored for further calculation and SHEET 3-6 need to be used. How to write
    such formula?
    How to get pop up alert for multiple rows, if a specific condition is hit?

    Maybe VBA Code should be a good option for you. I suggest you post you issue to
    Excel for Developers forum.
    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us.
    Thanks for your understanding.
    Best Regards,
    Wind

  • Merge multiple rows into single row (but multiple columns)

    How to merge multiple rows into single row (but multiple columns) efficiently.
    For example
    IDVal IDDesc IdNum Id_Information_Type Attribute_1 Attribute_2 Attribute_3 Attribute_4 Attribute_5
    23 asdc 1 Location USA NM ABQ Four Seasons 87106
    23 asdc 1 Stats 2300 91.7 8.2 85432
    23 asdc 1 Audit 1996 June 17 1200
    65 affc 2 Location USA TX AUS Hilton 92305
    65 affc 2 Stats 5510 42.7 46 9999
    65 affc 2 Audit 1996 July 172 1100
    where different attributes mean different thing for each Information_type.
    For example for Information_Type=Location
    Attribute_1 means Country
    Attribute_2 means State and so on.
    For example for Information_Type=Stats
    Attribute_1 means Population
    Attribute_2 means American Ethnicity percentage and so on.
    I want to create a view that shows like below:
    IDVal IDDesc IDNum Country State City Hotel ZipCode Population American% Other% Area Audit Year AuditMonth Audit Type AuditTime
    23 asdc 1 USA NM ABQ FourSeasons 87106 2300 91.7 46 85432 1996 June 17 1200
    65 affc 2 USA TX AUS Hilton 92305 5510 42.7 46 9999 1996 July 172 1100
    Thanks

    Hi,
    That's called Pivoting . The forum FAQ has a section on this subject: {message:id=9360005}
    I hope this answers your question.
    If not, post your best attempt, along with a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data. (You did post the results you wanted, but they're very hard to read because they're not formatted. Use \ tags, as described in the forum FAQ, below.)
    Explain, using specific examples, how you get the results you want from the data given.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).  This is always important, but especially so with pivots.
    See the forum FAQ {message:id=9360002}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Combine multiple rows in single row

    I am new to SQL server and i am trying to combine multiple row in single row but i am not able to do it.Can anyone help me out?
    Input :
    Id |RED |BUY |BSW
    1328 NULL NULL 0.05
    1328 NULL 0.06 NULL
    1328 0.01 NULL NULL
    1328 0.05 NULL NULL
    1329 NULL NULL 0.05
    1329 NULL 0.05 NULL
    1329 0.05 NULL NULL
    Output
    Id |RED |BUY |BSW
    1328 0.01 0.06 0.05
    1328 0.05 NULL NULL
    1329 0.05 0.05 0.05

    Actually I am consolidating above result into text file and sending it to external system.Main aim is to remove NULL values and arrange the data as expected output.
    Also expected output can be
    Id         |RED   
    |BUY    |BSW
    1328        0.05   
    0.06    0.05
    1328        0.01   
    NULL    NULL
    Or
    Id         |RED   
    |BUY    |BSW
    1328        0.01   
    0.06    0.05
    1328        0.05   
    NULL    NULL
    for Id= 1328.

  • How to use the same POWL query for multiple users

    Hello,
    I have defined a POWL query which executes properly. But if I map the same POWL query to 2 portal users and the 2 portal users try to access the same page simultaneously then it gives an error message to one of the users that
    "Query 'ABC' is already open in another session."
    where 'ABC' is the query name.
    Can you please tell me how to use the same POWL query for multiple users ?
    A fast reply would be highly appreciated.
    Thanks and Regards,
    Sandhya

    Batch processing usually involves using actions you have recorded.  In Action you can insert Path that can be used during processing documents.  Path have some size so you may want to only process document that have the same size.  Look in the Actions Palette fly-out menu for insert path.  It inserts|records the current document work path into the action being worked on and when the action is played it inserts the path into the document as the current work path..

  • Can I use Concatenate function for multiple rows?

    I have a lead list that contains 5000 leads. The format of this list contains address data that is saved in separate columns (ie: address, address 2, city, state, zip). I need this data in 1 column. I tried to use the concatenate function to combine the data for 1 row and it worked perfectly. I tried to do this for multiple rows and the function is greyed out. Is there a work around or way that I can combine this data for all 5000 rows without doing it 1 by one?

    Look at this table;
    In B9, the formula is;
    =B2&" "&C2&" "&D2&" "&E2&" "&B3&" "&C3&" "&D3&" "&E3
    Yvan KOENIG (VALLAURIS, France) dimanche 18 octobre 2009 20:51:47

  • Extended Program check for multipl programes in single run

    Hello All,
    I wan to do the syntax check for multiple programs at single execution run.
    SAP has provided SLIN transaction for single program, Is there any SAP standard transaction similar as SLIN for multiple program check at single execution run?
    Thanks,
    Feroz.

    >
    s feroz wrote:
    > I need it in R/34.6b version.
    I don't think you have much option there

  • Query for multiple invoice numbers.

    Hi,
    My question is if I can add multiple invoice numbers in the search field "invice number"?
    For example when I receive a balance confirmation request from a supplier and their list contains 10 invoices. Can I do a search for all 10 at the same time or I can olny do a search one by one?
    Thank you!
    Angie

    Hi,
    there's no direct possibility to query for multiple Invoice number in terms of entering e.g. 5 number for a query.
    But you can work with placeholders '_' and '%' to find multiple invoices at one time. Underscore sign stands
    for exactly one character which can have multiple value, percentage sign for multiple ones.
    Example (assuming you are using letters and numbers for invoice numbering):
    When entering 'A12_' as search String, invoices from 'A120' to 'A12z' would be found.
    When using 'A12_01_' all invoices from 'A120010' to 'A12z01z' would be found.
    When using 'A12%' all invoices starting with 'A12' - no matter about the rest would be found.
    These are only a few examples but i think when using a clever combination of wildcards and parts of the
    invoices - which often share a common component, if the invoices come from the same vendor - you'll get
    at least a small step farther.
    Regards

  • Looking for a best query for multiple IF Else statement in a single select

    Hi
    I want to run multiple IF Else statements in a single select SQL, each statement is one SQL operating on the same table, what is the best way to write this select SQL query ?
    If it is PL/SQL, when i get the result from the first IF statement I will skip the remaining execution, and so on... Can any one help me on this.
    Thanks in advance !!

    965818 wrote:
    I Apologize, the information i have given might not be enough.
    This is my scenario,
    I am selecting set of rows from the table for the employee id. After selecting those records,
    i need to go through the result list and check the condition 1, if it is met, i will return that employee record.
    If that condition 1 is not met, then i need to go through the condition 2. If that is met, i will return that record.
    Like wise, i have four conditions.
    I am trying to achieve this in a single sql. If i am not clear, please let me know.Not fully clear yet, but the picture is better already. The thing with SQL is that you should stop thinking procedurally. Instead think in data sets.
    For example if the task is:
    Find all managers that work in sales.
    Procedural thinking would work like this:
    pseudo code
    Loop over all employees that work in sales
       for each row
           check if it is a manager
               if manager
                  then return record
               else
                  do nothing
               end
    end loopThinking in datasets will result in a different logic
    pseudo code
    select all employees
    where department = SALES
    and job = MANAGERThis advantage here is that all the "Do nothing" loops are not needed. Those are already eliminated by the database.
    So what is needed to help you? Give the full picture. What is your task that you try to solve. From a business perspective.

  • Oracle query - Merging multiple rows into a single row output

    Hi All,
    I have to have a multiple row output to be converted into a single row output.My current output looks as follows:
    ID YR INC_CODE OFFN SCHOOLNO
    8006 2002 00175 SC03 12
    8006 2002 00175 DC06 12
    8006 2002 00175 DC03 12
    8006 2002 00175 DC02 12
    ID,INCIDENT CODE,OFFENSE are all Primary keys
    So I need the output as follows:(IN ONE ROW)
    ID YR INC_CODE OFFN1 OFFN2 OFFN3 OFFN4 SCHOOLNO
    8006 2002 00175 SC03 DC06 DC03 DC02 12
    Can you help me on this since have been spinning the wheel and this has to be a query since will have couple of tables join to produce a materialized view.
    Thanks in advance

    Hi Nigel,
    Thanks for the reply I tested out the portion having the decode and I get the output as follows:
    ID YR INC_CODE OFFN1 OFFN2 OFFN3 OFFN4 OFFN5
    8982 2002 2175 DOC01 -----------------------
    8982 2002 2175 DOC02-------------------
    8982 2002 2175 DOC03------------
    8982 2002 2175 DOC06-------
    8982 2002 2175 SCV03
    There is no value as max for OFFN and each INC_CODE MAY HAVE UP TO A MAX OF 5 OFFN.My query is as follows:
    select distinct STU_STUDENT_ID, INC_BEG_SCH_YR,INC_INCIDENT_CODE
    , decode(rank() over (partition by INC_CODE order by OFFN),1,OFFN,null) as offn1
    , decode(rank() over (partition by INC_CODE order by OFFN),2,OFFN,null) as offn2
    , decode(rank() over (partition by INC_CODE order by OFFN),3,OFFN,null) as offn3
    , decode(rank() over (partition by INC_CODE order by OFFN),4,OFFN,null) as offn4
    , decode(rank() over (partition by INC_CODE order by OFFN),5,OFFN,null) as offn5
    from stu_offn where
    stu_offn.ID = '8982' and stu_offn.INC_CODE = '2175'
    (****Where clause is just given to just check a value)
    So as you know I need to just have all the OFFN in a single row ie as follows:
    ID YR INC_CODE OFFN1 OFFN2 OFFN3 OFFN4 OFFN5
    8982 2002 2175 DOC01 DOC02 DOC03 DOC06 SCV03
    Can you just give me a step by step procedure to go through this and the table in this case is just 'STU_OFFN'
    Thanks for the earlier reply appreciate it!
    ****Sending this again to show the exact way the output is coming

  • Oracle Query failing for multiple rows:

    Hey Guys,
    I have been given a task to produce an ad-hoc report based on the following conditions (I will give you the structure of the table and details in the table below the requirements)
    Requirements: Adhoc Report for Audit on CIT Income Allocation
    1. Select from the RETURNS table:
    • Id > 3600000 and
    • Prog_program_cd = '01' and
    • Return_status in ('ASSESSED', 'DU") and
    • Tax year ending in 2009 (i.e. year portion of the Period_end_date is in 2009)
    2. Retrieve the following fields from the RETURNS table :
    • Id
    • Entp_abn
    • Acct_id
    • Prog_program_cd
    • Period_start_date
    • Period_end_date
    • Amend_ind
    • Return_status
    • Status_date
    • Loctr_nbr
    3. If there are multiple entries from the same account and tax year, only retain the latest record: From the records selected in step 2, if there are multiple records with the same Acct_Id and Period_end_date, only retain the record with the most recent Status_date (i.e. MAX value on the date).
    4. Using the results from step 3, link to the applicable RETURN_LINE_ITEMS table where:
    • RETURNS.Id = RETURN_LINE_ITEMS.Rtrn_Id
    5. From the selected return on RETURN_LINE_ITEMS table, retrieve records where (value on Sch 000 Line 062 > 500,000) and (value on Sch 000 Line 066 < value on Sch 000 Line 062) :
    • Sched_nbr = '000', and Litm_line_item_nbr = '062', and Active_ind = 'Y', get Revise_val_amt as 'ab_taxable_income'
    • Sched_nbr = '000', and Litm_line_item_nbr = '066', and Active_ind = 'Y', get Revise_val_amt as 'amt_taxable_in_ab'
    • Retain the return only if (ab_taxable_income > 500,000) and (amt_taxable_in_ab < ab_taxable_income)
    The tables used in this are : RETURNS and RETURN_LINE_ITEMS
    Structure of RETURNS table is:
    ID
    PROG_PROGRAM_CD
    ACCT_ID
    ACPE_ID
    JENT_ID
    PREV_RTRN_ID
    ENTP_ABN
    ACCT_OCCURNC_NBR
    SOURCE_TYPE
    RECEIVE_DATE
    AMEND_IND
    CMPLT_IND
    PENALTY_OR_IND
    RETURN_STATUS
    STATUS_DATE
    STATUS_USERID
    PERIOD_START_DATE
    PERIOD_END_DATE
    NOTICE_STATUS
    NOTICE_STATUS_DATE
    NOTE_TEXT
    PENALTY_OR_BY
    PENALTY_OR_TMST
    FILING_ID
    CASE_ID
    DOC_CONTRL_NBR
    LOCTR_NBR
    STATUTE_BARRED_DATE
    MEDIA_TYPE
    DISPSTN_TYPE
    AMEND_TYPE
    CALC_MODE
    PROCESS_PASS_CNT
    CONVRTD_IND
    LOSS_PERIOD_END_DATE
    MF_SYNC_CD
    CREATED_BY
    CREATED_TMST
    MODIFIED_BY
    MODIFIED_TMST
    Structure of RETURN_LINE_ITEMS is:
    ID
    RTSC_ID
    RTRN_ID
    SCLI_ID
    LITM_ID
    ENTP_ABN
    PROG_PROGRAM_CD
    ACCT_OCCURNC_NBR
    ACPE_END_DATE
    SCHED_NBR
    SCHD_VERSION_YR
    SCHD_VERSION_NBR
    RTSC_OCCUR_NBR
    LITM_LINE_ITEM_NBR
    SLIN_LINE_ITEM_ID
    OCCUR_NBR
    PREV_VAL_MOD_IND
    VIABLE_IND
    ACTIVE_IND
    ACTION_CD
    PREV_VAL_AMT
    REVISE_VAL_AMT
    PREV_VAL_TEXT
    REVISE_VAL_TEXT
    DISPLAY_SEQ_NBR
    SYS_VAL_AMT
    LITM_INNER_PASS_SEQ_NBR
    CREATED_BY
    CREATED_TMST
    MODIFIED_BY
    MODIFIED_TMST
    So scripts to create the able tables are:
    RETURNS
    CREATE TABLE RETURNS
    ID NUMBER(12),
    PROG_PROGRAM_CD VARCHAR2(2 BYTE),
    ACCT_ID NUMBER(12),
    ACPE_ID NUMBER(12),
    JENT_ID NUMBER(12),
    ENTP_ABN NUMBER(9),
    ACCT_OCCURNC_NBR NUMBER(4),
    SOURCE_TYPE VARCHAR2(30 BYTE) DEFAULT 'BLANK',
    RECEIVE_DATE DATE,
    AMEND_IND VARCHAR2(1 BYTE) DEFAULT 'N',
    CMPLT_IND VARCHAR2(1 BYTE) DEFAULT 'N',
    PENALTY_OR_IND VARCHAR2(1 BYTE) DEFAULT 'N',
    RETURN_STATUS VARCHAR2(12 BYTE),
    STATUS_DATE DATE,
    STATUS_USERID VARCHAR2(8 BYTE),
    PERIOD_START_DATE DATE,
    PERIOD_END_DATE DATE,
    NOTICE_STATUS VARCHAR2(12 BYTE),
    NOTICE_STATUS_DATE DATE,
    LOCTR_NBR NUMBER(10),
    MEDIA_TYPE VARCHAR2(30 BYTE),
    DISPSTN_TYPE VARCHAR2(30 BYTE),
    CONVRTD_IND VARCHAR2(1 BYTE) DEFAULT 'N')
    RETURN_LINE_ITEMS
    CREATE TABLE RETURN_LINE_ITEMS
    ID NUMBER(12),
    RTSC_ID NUMBER(12),
    RTRN_ID NUMBER(12),
    LITM_ID NUMBER(12),
    ENTP_ABN NUMBER(9),
    PROG_PROGRAM_CD VARCHAR2(2 BYTE),
    ACCT_OCCURNC_NBR NUMBER(4),
    ACPE_END_DATE DATE,
    SCHED_NBR VARCHAR2(3 BYTE),
    SCHD_VERSION_YR NUMBER(4) DEFAULT 0,
    SCHD_VERSION_NBR NUMBER(3),
    RTSC_OCCUR_NBR NUMBER(3),
    LITM_LINE_ITEM_NBR VARCHAR2(3 BYTE),
    SLIN_LINE_ITEM_ID NUMBER(12),
    OCCUR_NBR NUMBER(3) DEFAULT 1,
    PREV_VAL_MOD_IND VARCHAR2(1 BYTE) DEFAULT 'N',
    VIABLE_IND VARCHAR2(1 BYTE) DEFAULT 'N',
    ACTIVE_IND VARCHAR2(1 BYTE) DEFAULT 'Y',
    PREV_VAL_AMT NUMBER(15,2),
    REVISE_VAL_AMT NUMBER(15,2),
    DISPLAY_SEQ_NBR NUMBER(3),
    SYS_VAL_AMT NUMBER(15,2),
    LITM_INNER_PASS_SEQ_NBR NUMBER(3)
    So when you run the scripts above, the tables are created (I have tested it in TOAD)
    Now let's feed data into both the tables
    RETURNS table:
    insert into RETURNS
    VALUES
    (3602448 , '01' ,288151,3876821,9345370 , 403232531, 1, 'TAXPAYER' ,12/4/2008 ,'N', 'Y','N','ASSESSED', 2/18/2009,'SANDEEP',1/2/2008,1/2/2009,
    'PRINTED','2/18/2009, 6043073664,'PAPER', 'NOTICE','N');
    insert into RETURNS
    VALUES
    (4117092 , '01' ,57794,3864551,10566221 , 400571410, 1, 'TAXPAYER' ,6/30/2010 ,'N', 'Y','N','ASSESSED', 2/18/2009,'SANDEEP',1/2/2008,1/2/2009,
    'PRINTED','2/18/2009, 6043073664,'PAPER', 'NOTICE','N');
    RETURN_LINE_ITEMS table:
    INSERT INTO RETURN_LINE_ITEMS
    VALUES
    (266000770,7749234,3602448,1603,403232531, 01, 1, 1/1/2009, 000, 1998, 1,1, '062', 40,1, 'N','Y', -5440, -5440, 200,-5440,130);
    INSERT INTO RETURN_LINE_ITEMS
    VALUES
    (266000773,7749234,3602448,1539,403232531, 01, 1, 1/1/2009, 000, 1998, 1,1, '066', 43,1, 'N','Y', NULL, 0, 215,0,200);
    INSERT INTO RETURN_LINE_ITEMS
    VALUES
    (319820233,9028477,4117092,1603,400571410, 01, 1, 1/1/2009, 000, 1998, 1,1, '062', 40 ,1, 'N','Y', 790068, 790068, 200,790068,130);
    INSERT INTO RETURN_LINE_ITEMS
    VALUES
    (319820236,9028477,4117092,1539,400571410, 01, 1, 1/1/2009, 000, 1998, 1,1, '062', 40 ,1, 'N','Y', NULL, 790, 215,790068,200);
    This completes the test data.
    Now based on the question posed by the Business Analyst, until "5 b" i.e where it's said:
    Sched_nbr = '000', and Litm_line_item_nbr = '066', and Active_ind = 'Y', get Revise_val_amt as 'amt_taxable_in_ab'
    I am able to retrieve data perfectly fine and the query for that is:
    SELECT r1.id, r1.entp_abn, r1.acct_id, r1.prog_program_cd, r1.period_start_date, r1.period_end_Date, r1.amend_ind, r1.return_status, r1.status_date, r1.loctr_nbr,
    rtlnms.sched_nbr, rtlnms.litm_line_item_nbr,
    decode(rtlnms.litm_line_item_nbr, '062', RTLNMS.REVISE_VAL_AMT)AB_TAXABLE_INCOME,
    decode(rtlnms.litm_line_item_nbr, '066', RTLNMS.REVISE_VAL_AMT)AMT_TAXABLE_IN_AB
    from returns r1, return_line_items rtlnms
    where r1.id = rtlnms.rtrn_id
    and r1.id > 3600000
    AND r1.prog_program_cd = '01'
    AND r1.return_status in ('ASSESSED', 'DU')
    and r1.period_end_Date between to_date('01-01-2009','DD-mm-YYYY') and to_date ('31-12-2009', 'DD-mm-YYYY')
    and r1.status_date = (select max (status_date) from returns r2 where r2. acct_id= r1.acct_id and r2.period_end_date = r1.period_end_date)
    and rtlnms.sched_nbr = '000'
    and RTLNMS.LITM_LINE_ITEM_NBR IN('062', '066')
    and rtlnms.active_ind = 'Y' and r1.id in(4117092, 3602448)
    The out put is : 4 rows returned which has litm_line_item_nbrs for all the returns in question (4117092, 3602448) and that is - 066,062,062, 066 with their respective amounts.
    However against the business analyst's question 5 "C" which is - Retain the return only if (ab_taxable_income > 500,000) and (amt_taxable_in_ab < ab_taxable_income)
    I should be getting 2 rows(one with '062' and '066') with return -4117092
    So I am applying the logic as mentioned by business analyst's "5C" and run the following query:
    SELECT r1.id, r1.entp_abn, r1.acct_id, r1.prog_program_cd, r1.period_start_date, r1.period_end_Date, r1.amend_ind, r1.return_status, r1.status_date, r1.loctr_nbr,
    rtlnms.sched_nbr, rtlnms.litm_line_item_nbr,
    decode(rtlnms.litm_line_item_nbr, '062', RTLNMS.REVISE_VAL_AMT)AB_TAXABLE_INCOME,
    decode(rtlnms.litm_line_item_nbr, '066', RTLNMS.REVISE_VAL_AMT)AMT_TAXABLE_IN_AB
    from returns r1, return_line_items rtlnms
    where r1.id = rtlnms.rtrn_id
    and r1.id > 3600000
    AND r1.prog_program_cd = '01'
    AND r1.return_status in ('ASSESSED', 'DU')
    and r1.period_end_Date between to_date('01-01-2009','DD-mm-YYYY') and to_date ('31-12-2009', 'DD-mm-YYYY')
    and r1.status_date = (select max (status_date) from returns r2 where r2. acct_id= r1.acct_id and r2.period_end_date = r1.period_end_date)
    and rtlnms.sched_nbr = '000'
    and RTLNMS.LITM_LINE_ITEM_NBR IN('062', '066')
    and rtlnms.active_ind = 'Y' and r1.id in(4117092, 3602448)
    and r1.id in (select rtrn2.id
    from returns rtrn2, return_line_items rtlnms2
    where rtrn2.id= rtlnms2.rtrn_id
    and rtrn2.id=r1.id
    and nvl(decode(rtlnms.litm_line_item_nbr, '062', RTLNMS.REVISE_VAL_AMT),0) > 500000 or rtlnms2.litm_line_item_nbr='066') and (
    nvl(decode(rtlnms.litm_line_item_nbr, '066', RTLNMS.REVISE_VAL_AMT),0) < nvl(decode(rtlnms.litm_line_item_nbr, '062', RTLNMS.REVISE_VAL_AMT),0))
    order by r1.acct_id , r1.period_end_date desc
    I am only getting one row with for RETURN = 4117092 with litm_line_item_nbr (line item number) '062' where as I should also be getting line item number '066' along with '062'
    Could any one of you please help me out. I am stuck and have tried everything at the office with no luck.
    Many Many Thanks in Advance!
    Sandeep

    Hi there,
    I agree that without test case it's a bit complicated for you folks to solve. However I just could not. Anyways this is the query that I had to use to come to my solution and that is:
    SELECT r1.id, r1.entp_abn, r1.acct_id, r1.prog_program_cd, r1.period_start_date, r1.period_end_Date, r1.amend_ind, r1.return_status, r1.status_date, r1.loctr_nbr,
    rtlnms.sched_nbr, rtlnms.litm_line_item_nbr,
    decode(rtlnms.litm_line_item_nbr, '062', RTLNMS.REVISE_VAL_AMT)AB_TAXABLE_INCOME,
    decode(rtlnms.litm_line_item_nbr, '066', RTLNMS.REVISE_VAL_AMT)AMT_TAXABLE_IN_AB
    from returns r1, return_line_items rtlnms
    where
    r1.id = rtlnms.rtrn_id and
    r1.prog_program_cd = rtlnms.prog_program_cd and
    r1.entp_abn = rtlnms.entp_abn and
    r1.id > 3600000 AND r1.prog_program_cd = '01' AND r1.return_status in ('ASSESSED', 'DU')
    and r1.period_end_Date between to_date('01-01-2009','DD-mm-YYYY') and to_date ('31-12-2009', 'DD-mm-YYYY')
    and r1.status_date = (select max (status_date) from returns r2 where r2. acct_id= r1.acct_id and r2.period_end_date = r1.period_end_date)
    and rtlnms.sched_nbr = '000'
    and rtlnms.active_ind = 'Y'
    and r1.id in (4117092,3715944,4382179,3691435)
    and RTLNMS.LITM_LINE_ITEM_NBR IN('062')
    AND nvl(decode(litm_line_item_nbr, '062', REVISE_VAL_AMT),0) > 500000
    and NVL(RTLNMS.REVISE_VAL_AMT,0) >( select NVL(RTLNMS2.REVISE_VAL_AMT,0)
    FROM RETURN_LINE_ITEMS RTLNMS2
    WHERE RTLNMS2.RTRN_ID=RTLNMS.RTRN_ID
    AND RTLNMS2.LITM_LINE_ITEM_NBR = '066'
    AND SCHED_NBR='000'
    UNION
    SELECT r1.id, r1.entp_abn, r1.acct_id, r1.prog_program_cd, r1.period_start_date, r1.period_end_Date, r1.amend_ind, r1.return_status, r1.status_date, r1.loctr_nbr,
    rtlnms.sched_nbr, rtlnms.litm_line_item_nbr,
    decode(rtlnms.litm_line_item_nbr, '062', RTLNMS.REVISE_VAL_AMT)AB_TAXABLE_INCOME,
    decode(rtlnms.litm_line_item_nbr, '066', RTLNMS.REVISE_VAL_AMT)AMT_TAXABLE_IN_AB
    from returns r1, return_line_items rtlnms
    where r1.id = rtlnms.rtrn_id
    AND r1.prog_program_cd = rtlnms.prog_program_cd
    AND r1.entp_abn = rtlnms.entp_abn
    AND r1.id > 3600000 AND r1.prog_program_cd = '01'
    AND r1.return_status in ('ASSESSED', 'DU')
    and r1.period_end_Date between to_date('01-01-2009','DD-mm-YYYY') and to_date ('31-12-2009', 'DD-mm-YYYY')
    and r1.status_date = (select max (status_date) from returns r2 where r2. acct_id= r1.acct_id and r2.period_end_date = r1.period_end_date)
    and rtlnms.sched_nbr = '000'
    and rtlnms.active_ind = 'Y'
    and r1.id in (4117092,3715944,4382179,3691435)
    and RTLNMS.LITM_LINE_ITEM_NBR IN('066')
    and NVL(RTLNMS.REVISE_VAL_AMT,0) <( select NVL(RTLNMS2.REVISE_VAL_AMT,0)
    FROM RETURN_LINE_ITEMS RTLNMS2
    WHERE RTLNMS2.RTRN_ID=RTLNMS.RTRN_ID
    AND RTLNMS2.LITM_LINE_ITEM_NBR = '062'
    and NVL(RTLNMS2.REVISE_VAL_AMT,0)>500000
    AND SCHED_NBR='000'
    order by ID
    This above query works fine. No worries.
    One more question and that is:
    I need to find out details of another condition. However what happens is using the same query above, when I try to add "and RTLNMS.LITM_LINE_ITEM_NBR IN('066' ,029')" (in the bold part),
    it does give me another extra value for row 029 and that's something that I don't want. Based on the above results, I get 4 rows ; 2 each for 062 and 069.
    The question asked by business is based on the above results, bring out even values for 029, so which in this case should be 2 rows, making it overall 6, but then I get 7, is there any way to get rid of extra row
    or rather : is there any way to retrieve additional row based on results from a query?

Maybe you are looking for

  • Sales order need to be blocked for delivery while creation

    Hi experts,                 My requirement is to block sales orders for delivery, for the selected distribution channels, and for selected countries while creation itself, so for this I came to known that a program MV45AFZZ include, here in this at w

  • Who can I contact about getting some help with this ongoing (several months) issue???

    I will try to make a long story at least somewhat shorter.Comcast customer for 20 years (yes - literally 20 uninterrupted years). 8 years of service at current address.Several months ago I restructure my bill - all my promotions etc had run out and I

  • Cost For exhange of data using SAP XI

    Hi All, For all exchange of data between legacy and SAP R/3 will their be any trasaction charges (given to SAP )involved for the data transfer using SAP XI or is it based upon the license which we have received for number of users. i.e If I am creati

  • Vision Builder 7.1

    Mi programa lo realicé en LabVIEW 7.1 versión estdiantil, y tengo el LabVIEW Signal and Image Processing Add-Ons, igual, versión estudiantil. Las dudas que tengo son del funcionamiento del Visioin Builder 7.1 1.- En la clasificación de imágenes, el V

  • SM30 issue

    I created a ZTABLE with table maintenance generator. It works well in Development System when I maintain using Tcode SM30 but when I transported to Quality system it shows the following error. Stop sign with the following message Check maintenance ob