Dynamic column output based on selection.

Hi all,
I have certain qualification select-options upon the selection-screen.
I have 5001 to 5012 range of qualificaitons.
If user select only 5001 to 5003....
I want only 3 columns ...or else if user wants to select 5008 to 5012  output should be have columns 5008 , 09,10,11...
I am displaying output in
mail format only
concanate 'COL1' COL2' 'COL2' TO STRING SEPERATED BY C=>LB.
loop at itab.
CONCATE ITAB-1 itab-2 itab-3 to Xstring.
endloop.
Thanks and regards
sas
Edited by: saslove sap on Jul 7, 2010 5:36 AM

Well I have harcoded the value  as below.I have no choice find .  Instead of using mutiple 'IF' conditions ANY other options are left:
  CONCATENATE
  'Personnel Number'    'Employee GUID'   'Last Name'   'First Name'   'Position Number'   'Position Title'   'Department Number'
  'Department Name'    'Employee Subgroup text'    'Employee Group text'   'SBU Head Personnel Number'   'SBU Head GUID'
  'SBU Head Name'   'Supervisor Personnel Number'   'Supervisor GUID'   'Supervisor Name'
  'Personnel Subarea text'
'CF1-Director function'
'CF2-Nonexecutive director function'
'CF3-Chief Executive function'
'CF8-Apportionment & oversight function'
'CF10-Compliance oversight function'
'CF11-Money laundering reporting function'
'CF28-Systems & controls function'
'CF29-Significant management function'
'CF30-Customer function, Investment Advice'
'CF30-Customer function, Investment Mgmt'
'CF30-Customer function, Trading'
'Admin - FSA T&C qualifying role'
    INTO S_OUTPUT-X SEPARATED BY C_TAB.
IF C = 'X'.
IF '50000001' IN s_quali[].
   CONCATENATE S_OUTPUT-X    'CF1-Director function'  INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000002' IN s_quali[].
   CONCATENATE S_OUTPUT-X    'CF2-Nonexecutive director function' INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000003' IN s_quali[].
   CONCATENATE S_OUTPUT-X    'CF3-Chief Executive function' INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000004' IN s_quali[].
   CONCATENATE S_OUTPUT-X    'CF8-Apportionment & oversight function' INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000005' IN s_quali[].
   CONCATENATE S_OUTPUT-X    'CF10-Compliance oversight function' INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000006' IN s_quali[].
   CONCATENATE S_OUTPUT-X    'CF11-Money laundering reporting function' INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000007' IN s_quali[].
   CONCATENATE S_OUTPUT-X    'CF28-Systems & controls function' INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000008' IN s_quali[].
   CONCATENATE S_OUTPUT-X    'CF29-Significant management function' INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000009' IN s_quali[].
   CONCATENATE S_OUTPUT-X    'CF30-Customer function, Investment Advice' INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000010' IN s_quali[].
   CONCATENATE S_OUTPUT-X    'CF30-Customer function, Investment Mgmt' INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000011' IN s_quali[].
   CONCATENATE S_OUTPUT-X    'CF30-Customer function, Trading' INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000012' IN s_quali[].
   CONCATENATE S_OUTPUT-X    'Admin - FSA T&C qualifying role' INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
endif.
  APPEND S_OUTPUT.
  LOOP AT GIT_ITAB ASSIGNING <GFS_ITAB>.
    CLEAR S_OUTPUT.
    CONCATENATE
<GFS_ITAB>-PERNR <GFS_ITAB>-EMPGUID <GFS_ITAB>-LNAME  <GFS_ITAB>-FNAME  <GFS_ITAB>-POSITION  <GFS_ITAB>-POSTITLE <GFS_ITAB>-DEPTNO <GFS_ITAB>-DEPTNAME  <GFS_ITAB>-EMPSUBTEXT <GFS_ITAB>-EMPGRPTEXT
<GFS_ITAB>-SBUNO <GFS_ITAB>-SBUGUID <GFS_ITAB>-SBUNAME <GFS_ITAB>-SUPVNO <GFS_ITAB>-SUPVGUID <GFS_ITAB>-SUPVNAME <GFS_ITAB>-PSUBAREATEXT
   INTO S_OUTPUT-X SEPARATED BY C_TAB.
IF C = 'X'.
IF '50000001' IN s_quali[].
   CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF1  INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000002' IN s_quali[].
   CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF2 INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000003' IN s_quali[].
   CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF3 INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000004' IN s_quali[].
   CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF4 INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000005' IN s_quali[].
   CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF5 INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000006' IN s_quali[].
   CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF6 INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000007' IN s_quali[].
   CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF7 INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000008' IN s_quali[].
   CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF8 INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000009' IN s_quali[].
   CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF9 INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000010' IN s_quali[].
   CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF10 INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000011' IN s_quali[].
   CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF11 INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
IF '50000012' IN s_quali[].
   CONCATENATE S_OUTPUT-X    <GFS_ITAB>-CF12 INTO S_OUTPUT-X SEPARATED BY C_TAB.
endIF.
endif.
  <GFS_ITAB>-CF2  <GFS_ITAB>-CF3 <GFS_ITAB>-CF4   <GFS_ITAB>-CF5 <GFS_ITAB>-CF6
<GFS_ITAB>-CF7  <GFS_ITAB>-CF8 <GFS_ITAB>-CF9 <GFS_ITAB>-CF10  <GFS_ITAB>-CF11  <GFS_ITAB>-CF12
*concatenate s_output-x c_cr into s_output-x.
    APPEND S_OUTPUT.
  ENDLOOP.

Similar Messages

  • Creating a Dynamic Update Statement based on Select

    hi,
    i'm trying to create a dynamic update statement based on select statement
    my requirment is to query a joint tables and get the results then based on the results i need to copy all the data and create an update statement for each row
    for ex
    the update statement should look like this
    update iadvyy set SO_SWEEP_CNT = '1' where inst_no = '003' and memb_cust_no = 'aaaaaaaaaaaaaaaa';
    and the select statement like the following
    select substr(key_1,11,9) account_no,sord_mast SO_SWEEP_CNT from
    select acct_no,count(*) sord_mast from
    (select from_acct_no acct_no,update_mast
    from sord where FROM_SYS in ('DEP','INV') and TERM_DATE > 40460
    union all
    select to_acct_no acct_no,update_mast
    from sord where TO_SYS in ('DEP','INV') and TERM_DATE > 40460)
    group by Acct_no)
    right outer join
    invm
    on
    key_1 = '003'||acct_no
    where sord_mast > 0;
    so taking the above two columns from the above select statement and substitue the values as separate update statement.
    is that doable , please share your knowledge with me if poosible
    thanks in advanced

    is that doable , please share your knowledge with me if poosibleyes
    The standard advice when (ab)using EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
    Then print the SQL before passing it to EXECUTE IMMEDIATE.
    COPY the statement & PASTE into sqlplus to validate its correctness.

  • Output based on selection

    Hi all,
    i'm working on MM report,
    i got one field in selection screen as
    PRODUCT TYPE = -
    (eg 6A, 6B, 6C)
    if i execute result should be based on this..
    if PRODUCT TYPE = -
    (eg 1A, 2B)
    it should give some other output....
    and should not take 6A, 6B in selection.
    how to approach this......
    Regards
    Suprith

    Hi suprit,
    select options s_prv .....
    in select stmt
    select * from table into internal table where prv in s_prv..
    the result vil b in ur internal table...
    Regards,
    Vamshi

  • Dynamic Column Formula based on Prompt

    Hi,
    i've defined a prompt and a presentation variable associated called "Scenario". It can assume values "Actual" or "Budget"
    My Subject Area contains vary dimensions and a fact table called "Productivity Measures" with following fields: "Productivity Actual" - "Productivity Budget"
    I've created a report with an only field (Header: 'Productivity") which retrieves data from my "Productivity Measures" fact table.
    Now i want that if Scenario value is Actual, the column formula of my field is "Productivity Measures"."Productivity Actual", otherwhise if Scenario value is Budget, the column formula of my field change dinamically to "Productivity Measures"."Productivity Budget". Is it possible? How can i do?

    Hi user,
    Why cant you write a case statement on the column defined i.e. when you select actual you get what you want and viceversa
    eg:- CASE '@{scenario}'
    WHEN 'Actual' THEN 'Productivity Actual'
    WHEN 'Budget' THEN 'Productivity Budget'
    ELSE 'Productivity Actual'
    END
    In case of prompt_column you declared variable right,you can call it there or directly use column name.
    Hope it helps you with this.
    By,
    KK
    Edited by: Kranthi on Dec 16, 2010 11:21 PM

  • To fetch column values based on selected month and year

    Hi,
    I have a requirement where I have 2 prompts Fiscal Year and month on a report.
    Therefore when I select Year and the month I should get the ID's for the selected month till the first month of that fiscal year.
    E.g By selecting July  and year 2013 I should get all the id's in the report from Jan 2013 till July 2013.
    How to acheive his in OBIEE. Please help.

    what is the column for comparing these two dates ? I am considering CALENDAR_DATE
    CALENDAR_DATE BEWEEN
    CAST(concat('01-JUL-', (CASE WHEN pv_month in ('JAN', 'FEB', 'MAR') THEN CAST(((CAST(RIGHT(pv_Year),4) AS INT) -1) as CHAR) ELSE CAST((RIGHT(v_Year),4) as CHAR) END)) AS  DATE)
    AND
    CAST(concat(concat(concat('01-', v_month),'-'),(CASE WHEN v_month in ('JAN', 'FEB', 'MAR') THEN CAST(((CAST(RIGHT(v_Year),4) AS INT) -1) as CHAR) ELSE CAST((RIGHT(v_Year),4) as CHAR) END) AS DATE)
    This logic might work, just play around type casting..
    Regards,
    Srinivas

  • String column output concate using select

    <pre>
    Hi,
    I've created a table like below details:
    create table name(
    seq number(2)
    name varchar2(100)
    Insert into name (SEQ, NAME) Values (1, 'CHARLES CLARKSON');
    Insert into name (SEQ, NAME) Values (2, 'CAROLINE SINCLAIR CLARKSON');
    COMMIT;
    select * from name;
    SEQ      NAME
    1     CHARLES CLARKSON
    2     CAROLINE SINCLAIR CLARKSON
    Now I want the output of name to be concatenated using a query, separated by comma(,). So I want the result as below:
    NAME
    CHARLES CLARKSON,CAROLINE SINCLAIR CLARKSON
    Is there any way we can achieve this concat?
    Thanks
    Deepak
    </pre>

    Like this:
    SQL> ed
    Wrote file afiedt.buf
      1  select rtrim(xmlagg(xmlelement(e,user_name||',').extract('//text()')),',') username
      2* from (SELECT user_name from table1 where rownum < 5) e
    SQL> /
    USERNAME
    MCNILA,BINGHA,AMORA,AMARK
    SQL>
    SQL> ed
    Wrote file afiedt.buf
      1  select rtrim(xmlagg(xmlelement(e,user_name||',').extract('//text()')),',') username
      2  from (SELECT 'CHARLES CLARKSON' user_name from dual
      3        union select 'CAROLINE SINCLAIR CLARKSON' from dual
      4*       union select 'FIRSTNAME LASTNAME ' from dual) e
    SQL> /
    USERNAME
    CAROLINE SINCLAIR CLARKSON,CHARLES CLARKSON,FIRSTNAME LASTNAME
    SQL> Edited by: AP on Aug 10, 2010 3:45 AM

  • Requirement  output based on Selection screen

    I have the data like this and need to have a report as per the below requirement
    Please experts guide me how to acheive this.
    RECORDCompcode div category       SalesOrg          Price      
    1     1208      A1      -           -     950     
    2     1208      A1     CA1           -       900      
    3     1208      A1     CA2           -     850     
    4     1208      -      -          4001     920     
    5     1208      -      -          4002     880     
    6     1208      A1      -          4001     700     
    7     1208      A2      -          4001     800     
    8     1208      A1     CA1           -     910     
    1.When the user runs the report, the target should be shown for only the selected values.
    Ex1 : User runs a report with selection (Company Code = 1208) and (Division = A1)
    With this combination target value should be shown as 950 - only the 1st record should be taken into account and should display that only.
    Ex2 : User runs a report with selection (Company Code = 1208) and (Salesorg = 4001)
    With this combination target value should be shown as 920 - only the 4th record should be taken into account and should display that only.
    2.After the initial run when the user drilldown any character, the target value defined by the drilled down character should be seen.
    Ex1 : User runs a report with selection (Company Code = 1208) and (Division = A1)
    With this combination target value should be shown as 950 - only the 1st record should be taken into account and should display that only.
    After the initial run, the user drilldown the report by Category. In this case target value 900 & 850 (records 2 & 3) should be shown respectively for categories Ca1 & Ca2 like below;
    Category Price
    C1       900
    C2       850
    Edited by: govaabaper on Dec 10, 2010 4:45 PM
    Edited by: govaabaper on Dec 13, 2010 8:07 AM

    Based on some assumptions and the date you have provided
    Ex1 : User runs a report with selection (Company Code = 1208) and (Division = A1)
    With this combination target value should be shown as 950 - only the 1st record should be taken into account and should display that only
    --> select the key figure aggregation as - Maximum-
    or if you can give the date/timestamp in the query as well- select the date and set it in the filter to be maximum- through a variable
    2.After the initial run when the user drilldown any character, the target value defined by the drilled down character should be seen.
    -->create a hierarchy on company code- division and place your category int he relevant divisions- when you activate the hierarchy it will show up as you have said

  • Hide Dynamic columns and remove space

    I have an application that allows users to generate a Crystal report containing selected columns.  A user is able to check which columns should appear on the report from a web page.  I'm able to display and suppress the dynamic columns but the space for the dynamic columns that are not selected remains.  How can I remove the space and have the columns move to the left?  
    I'm using VS 2003 and Crystal 10.

    As Ludek mentioned you would need to use the RAS .NET SDK to completely remove the column from the report. What you could do is start with a blank report, only have your database info added, then build UP your report rather than remove items. The ReportObjectController has a method called AddByName() that will insert a field into your report. It will add the field from left to right with a small buffer space.
    In order to use the RAS .NET SDK with Visual Studio .NET you'll need to upgrade to Crystal Reports 2008 or Crystal Reports for Visual Studio 2010 (good free price here).
    [RAS .NET Developer Guide|http://help.sap.com/businessobject/product_guides/boexir31/en/rassdk_net_dg_12_en.chm]
    [RAS .NET API Ref|http://help.sap.com/businessobject/product_guides/boexir31/en/rassdk_net_apiRef_12_en.chm]

  • Displaying dynamic columns in the query output.

    Hello,
    Depending on current quarter output of the query would vary.
    If current quarter is 'Q1'
    O/p : InvQ1  Del  BackQ1  BackQ2  BackQ3  BackQ4
    If current quarter is 'Q2'
    O/p : InvQ1  InvQ2  Del  BackQ2  BackQ3  BackQ4
    If current quarter is 'Q3'
    O/p : InvQ1  InvQ2  InvQ3  Del  BackQ3  BackQ4
    If current quarter is 'Q4'
    O/p : InvQ1  InvQ2  InvQ3  InvQ4  Del  BackQ4
    So, out of 9 columns, 6 columns would display at any given time depending on the current quarter.
    Invoice of 4 quarters, Deliquency and Backlog of 4 quarters.
    I am not getting any way how to display dynamic columns or hide unwanted/blank columns.
    For the time being I have added all 9 columns in the query, and in the output unwanted columns shows blank.
    Can anybody please suggest me how to display only 6 columns in the output depending on current quarter.
    Thanks and Regards
    Shilpa

    Hello,
    This shouldn't be too difficult. Assuming you have a variable with the selected quarter, you may choose to display Inv (whatever that is) for quarters 1 through variable, Del, and Back for quarters variable through 4. You also need a drilldown on quarter in the columns (after the key figure structure). You would probably need to restrict 'Del' on the variable as well if you haven't already done it.
    Best regards,
    Christoffer

  • Select dynamic columns

    Hi,
    We have a table with the output as JAN to DEC as column names. we want to give output based on the start date and endate. for ex: if 1/1/2009 and 31-04-2009 as input dates, then we want only JAN, FEB, MAR, APR columns.
    any suggestion?
    thanks,

    Hmmm... Seems I have too much free time at hand right now ;-)
    CREATE OR REPLACE FUNCTION FGetMonthList (dInputDate1 DATE, dInputDate2 DATE)
       RETURN VARCHAR2
    IS
       sMonthList     VARCHAR2 (1024) := '';
       nDateDiff      NUMBER          := 0;
       dDateCounter   DATE            := dInputDate1;
    BEGIN
       nDateDiff := ABS(dInputDate2 - dInputDate1);
       FOR nCounter IN 1 .. nDateDiff + 1
       LOOP
          IF sMonthList IS NOT NULL
          THEN
             IF INSTR (sMonthList, TO_CHAR (dDateCounter, 'MON')) = 0
             THEN
                sMonthList := sMonthList || ',' || TO_CHAR (dDateCounter, 'MON');
             END IF;
          ELSE
             sMonthList := TO_CHAR (dDateCounter, 'MON');
          END IF;
          dDateCounter := dDateCounter + 1;
       END LOOP;
       RETURN sMonthList;
    EXCEPTION
       WHEN OTHERS
       THEN
          RAISE_APPLICATION_ERROR
                             (-20935,
                              'Please pass valid date values as input parameters'
    END;
    SQL> SELECT FGetMonthList (SYSDATE, SYSDATE - 234) FROM Dual;
    FGETMONTHLIST(SYSDATE,SYSDATE-234)
    APR,MAY,JUN,JUL,AUG,SEP,OCT,NOVYou can utilize this function in your procedure now. I am sure there will be a smarter method of obtaining the month list but I am not an expert at PL/SQL.

  • Dynamic column selection

    I want to select specific columns from a table dynamically which are basically the columns returned by quering the user_tab_columns data dictionary which in turn has to satisfy certain condition for me.
    So, what I want to do is something like:
    SELECT b.(dynamic column list from a)
    FROM b,
    (SELECT column_name FROM user_tab_columns WHERE table_name='STH' AND ........) a
    any help will be greatly appreciated.

    sql>create or replace procedure p_dynamic_sql
      2  is
      3    v_sql varchar2(4000);
      4  begin
      5    v_sql := 'select ';
      6    for r in (select column_name
      7                from user_tab_cols
      8               where table_name = 'EMP'
      9                 and column_name like 'E%') loop
    10      v_sql := v_sql || r.column_name || ',';
    11    end loop;
    12    v_sql := rtrim(v_sql, ',') || ' from emp';
    13    dbms_output.put_line( v_sql );
    14    -- do something with SQL (open cursor, etc.)   
    15  end;
    16  /
    Procedure created.
    sql>exec p_dynamic_sql
    select EMPNO,ENAME from emp
    PL/SQL procedure successfully completed.

  • Cannot use alias for dynamic column name in SELECT statement

    Hi,
    I want to retrieve values from several tables by using dynamic column & table name as below:
    DATA: tbl_name(30) TYPE c VALUE '/bic/tbi_srcsys',  " staticly initialized for this example
               col_name(30) TYPE c VALUE '/bic/bi_srcsys'.  " staticly initialized for this example
    SELECT (col_name) INTO CORRESPONDING FIELDS OF TABLE it_values FROM (tbl_name).
    The internal table "it_values" does not contain a field named "/bic/bi_srcsys", instead it has another generic field "value" so that the above code can be applied to other tables. I tried to use alias (AS) as below:
    SELECT (col_name) AS value INTO CORRESPONDING FIELDS OF TABLE it_values FROM (tbl_name).
    But this cannot work. I know that there are other ways to solve this problem, such as by using a single field in SELECT .. ENDSELECT and subsequently appending it to the work area and internal table as below:
    SELECT (col_name)  INTO (lv_value) FROM (tbl_name).
      wa_value-value = lv_value.
      APPEND wa_value TO it_values.
    ENDSELECT.
    Just wonder if there is any other more elegant workaround, because I might have several other fields instead of only one?
    Thanks.
    Regards,
    Joon Meng

    Hi Suhas,
    thanks for the quick reply.
    Sorry that I have not well described the structure of the internal table "it_values". This internal table contains several other fields (key, type, value, etc.).
    I guess that the following code
    SELECT (col_name) INTO TABLE it_values FROM (tbl_name).
    works if the internal table only has one field (value) or the field "value" is in the first position, right?
    In this case, I need to fill the "value" field of internal table it_values (ignore the other fields like type, key) with values retrieved from (col_name) of the DDIC table.
    Looking forward to your reply.
    BR,
    Joon Meng

  • Dynamic bar chart based on LOV selected

    Apex 2.1 with XE : running on windows xp.
    I am trying to create charts based on selected criteria such as level 1, level 2 and level 3. If the user selects level 1 chart is expected to group level 2 and level 3 parameters else if the user selects level 2 criteria on top of level 1 then it should filter to the next category and so on. To make it simple I created three different queries which would generate the required graphs.
    To achieve this I decided to use PL/SQL function that would return three different chart queries based on the LOV selection. Although the function works well for each of the queries they dont work with a if else condition based on LOV selection. So what is the problem with creating such as dynamic query. Can I use the "%" values of LOV in my if else condition if not why ?
    Any alternatives ?

    Well. The queries for the charts run independently well. I guess I might be using the if else condition in an improper fashion.
    If the second LOV filter is not used.. I am matching the :LOV2 value with "%" and execute appropriate chart query based on single selection criteria and for the else case I use the other query and so on.
    I wish to show the code but since I upgraded to 3.0.1 today my application page views don't render properly. The images are missing ..and whole page is missing for editing.

  • Dynamic column names in Oracle

    HI SOS!! calling for help...
    i am trying to query the following. I want to remove the duplicates in the ID, and combine them into one... While doing so, I want to keep the data as it is by creating dynamic columns reason_1, reason_2, reason_3 with their corresponding TIME. In case of same reasons, I want to add the TIME. The database is as follows:
    ID     REASON     TIME
    A     41A..........     27
    A     93K..........16
    B     89C...........3
    B     93K...........7
    B     48C..........     4
    C     93K..........     24
    C     93K..........     7
    C     48C.........10
    Expected Result is
    ID     REASON_1......TIME_1.... REASON_2...TIME_2....REASON_3.........TIME_3
    A........ 41A............ 27........... 93K............16          
    B........ 89C............ 3............ 93K............7...........48C.................. 4
    C........ 93K........... 31.......... 48C..............10          
    Would be grateful if someone could try helping me out of this as early as possible.
    Edited by: 968125 on Oct 28, 2012 11:01 PM

    You still haven't made it clear what the requirement is.
    Is there a maximum number of reasons that can occur per ID? If so, you can code the pivoting of your data with something like:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'A' as ID, '41A' as reason, 27 as time from dual union all
      2             select 'A', '93K', 16 from dual union all
      3             select 'B', '89C', 3 from dual union all
      4             select 'B', '93K', 7 from dual union all
      5             select 'B', '48C', 4 from dual union all
      6             select 'C', '93K', 24 from dual union all
      7             select 'C', '93K', 7 from dual union all
      8             select 'C', '48C', 10 from dual)
      9  --
    10  -- END OF TEST DATA TABLE SIMULATED USING 'WITH' CLAUSE
    11  -- SIMPLY USE THE SELECT STATEMENT BELOW ON YOUR OWN TABLE
    12  --
    13  select id
    14        ,max(decode(rn,1,reason)) as reason_1
    15        ,max(decode(rn,1,time)) as time_1
    16        ,max(decode(rn,2,reason)) as reason_2
    17        ,max(decode(rn,2,time)) as time_2
    18        ,max(decode(rn,3,reason)) as reason_3
    19        ,max(decode(rn,3,time)) as time_3
    20        ,max(decode(rn,4,reason)) as reason_4
    21        ,max(decode(rn,4,time)) as time_4
    22        ,max(decode(rn,5,reason)) as reason_5
    23        ,max(decode(rn,5,time)) as time_5
    24  from (/* assign some row numbers within each ID, ordering by 'reason' then 'time' */
    25        select id, reason, time
    26              ,row_number() over (partition by id order by reason, time) as rn
    27        from   t
    28       )
    29* group by id
    SQL> /
    I REA     TIME_1 REA     TIME_2 REA     TIME_3 REA     TIME_4 REA     TIME_5
    A 41A         27 93K         16
    B 48C          4 89C          3 93K          7
    C 48C         10 93K          7 93K         24In this example, it will cater for up to 5 reasons/times per ID... and you can code for more if you need very easily.
    Also, as you're using 11g, you can use the new PIVOT query, for which you can find plenty of examples if you google or search these forums, or follow the FAQ link.
    If you don't have any idea how many reasons there could be, then you really are looking at generating columns dynamically.
    The problem with that is, because Oracle needs to know the SQL projection (see the FAQ link already provided), it has to know how many columns are going to be returned from a query before any data is fetched... but you are saying that the columns returned have to be based on the data itself. To do that you have two main options:
    1) You query the data once to determine how many columns you are going to need and then dynamically build up a query in PL/SQL code with the right number of columns (or use one of the other dynamic methods shown in the FAQ)
    or
    2) You step back and ask yourself if SQL is really the best place to be trying to produce this output. Reporting tools are often better suited to this requirement as they are made to query the data back from a database and then pivot and layout the data based on the data returned.

  • Dynamically Pass the Column Name cursor. || Dynamic Column Name

    Hi,
    I need to dynamically pass the column name based on a Mapping table in a loop ( Right now i have hardcoded stuff )just like using Execute immediate.... Inside the procedure, I have commented as where i hit the problem.
    Thanks for all of your time...
    Thanks
    Muthu
    CREATE OR REPLACE PROCEDURE xml_testing_clob AS
    doc xmldom.DOMDocument;
    main_node xmldom.DOMNode;
    root_node xmldom.DOMNode;
    user_node xmldom.DOMNode; item_node xmldom.DOMNode;
    root_elmt xmldom.DOMElement;
    item_elmt xmldom.DOMElement;
    item_text xmldom.DOMText;
    item_test xmldom.DOMText;
    nodelist xmldom.DOMNodeList;
    sub_variable varchar2(4000);
    x varchar2(200);
    y varchar2(200);
    sub_var varchar2(4000);
    CURSOR get_users IS
    SELECT FIRST_NAME,LAST_NAME,ROWNUM FROM USER_INFO_TBL WHERE WEIN_NUMBER = '1234' ;
    CURSOR get_cdisc_name IS
    select CTS_COL_NAME,CDISC_NAME from CTS2CDISC_DICTIONARY where CTS_TABLE_NAME = 'USER_INFO_TBL';
    BEGIN
    -- get document
    doc := xmldom.newDOMDocument;
    doc := xmldom.NewDomDocument;
    xmldom.setVersion(doc, '1.0');
    xmldom.setStandalone(doc, 'no');
    xmldom.setCharSet(doc, 'ISO-8859-1');
    -- create root element main_node := xmldom.makeNode(doc);
    root_elmt := xmldom.createElement(doc,'AdminData');
    root_node := xmldom.appendChild(main_node,xmldom.makeNode(root_elmt));
    FOR get_users_rec IN get_users LOOP
    item_elmt := xmldom.createElement(doc,'User');
    xmldom.setAttribute(item_elmt,'OID' , get_users_rec.rownum);
    user_node := xmldom.appendChild(root_node,xmldom.makeNode(item_elmt));
    FOR cv_get_cdisc_name IN get_cdisc_name LOOP
    EXIT WHEN get_cdisc_name%NOTFOUND;
    sub_var := cv_get_cdisc_name.cts_col_name;
    sub_variable := 'get_users_rec.';
    sub_variable := 'get_users_rec.'||cv_get_cdisc_name.cts_col_name;
    x := sub_variable;
    dbms_output.put_line(x); -------------- Here i just see the literal string
    y := get_users_rec.FIRST_NAME;
    dbms_output.put_line(y); -------------- Here i just see actual value ( data )
    item_elmt := xmldom.createElement(doc,cv_get_cdisc_name.cdisc_name);
    item_node := xmldom.appendChild(user_node,xmldom.makeNode(item_elmt));
    item_text := xmldom.createTextNode(doc,x ); ---- This is the place i am hitting with an error .
    If i use variable X then i am able to see only the literal
    string in the output. BUT if i put cursor name.coulmname,
    then the resumt (XML) is fine.I wanted acheive this
    dynamically just like execute Immediate
    item_node := xmldom.appendChild( item_node , xmldom.makeNode(item_text));
    END LOOP;
    END LOOP;
    -- write document to file using default character set from database
    xmldom.WRITETOCLOB(doc,);
    xmldom.writeToFile(doc, 'c:\ash\testing_out.xml');
    -- free resources
    xmldom.freeDocument(doc);
    END;
    +++++++++++++++++++++++++++++++++++ XML OUTPUT +++++++++++++++++++++++++++++++++++++++++
    <?xml version="1.0" ?>
    - <AdminData>
    - <User OID="1">
    <FirstName>get_users_rec.FIRST_NAME</FirstName>
    <LastName>get_users_rec.LAST_NAME</LastName> </User>
    - <User OID="2">
    <FirstName>get_users_rec.FIRST_NAME</FirstName>
    <LastName>get_users_rec.LAST_NAME</LastName>
    </User>
    - <User OID="3">
    <FirstName>get_users_rec.FIRST_NAME</FirstName>
    <LastName>get_users_rec.LAST_NAME</LastName>
    </User>
    - <User OID="4">
    <FirstName>get_users_rec.FIRST_NAME</FirstName>
    <LastName>get_users_rec.LAST_NAME</LastName>
    </User>
    - <User OID="5">
    <FirstName>get_users_rec.FIRST_NAME</FirstName>
    <LastName>get_users_rec.LAST_NAME</LastName>
    </User>
    ++++++++++++++++++++++++++++++++++++++++++++++++++++ MAPPING TABLE DETAILS +++++++++++++++++
    CTS_COL_NAME     CDISC_NAME     CTS_TABLE_NAME     XML_TAG     -----------> Column Name
    FIRST_NAME     FirstName     USER_INFO_TBL     Element     -----------> Records
    LAST_NAME     LastName     USER_INFO_TBL     Element     -----------> Records

    My scenario is little different, let me explain:
    My columns will remain same but values changes (based on column formula) according to the selected prompt value
    If I select 'Oct' from prompt then
    Curr will contain data for 'Oct' only
    Next1 will contain data for 'Nov' only
    Next2 will contain data for 'Dec' only
    Next3 will contain data for 'Jan' of next year only.
    Later if I select 'Jul' from prompt then
    Curr will contain data for 'Jul' only
    Next1 will contain data for 'Aug' only
    Next2 will contain data for 'Sep' only
    Next3 will contain data for 'Oct' only.
    I don't have different columns for each months but the columns are capable to reflect data for any month.
    So, how can I reflect the column name as month name for which that contains data.
    Regards,
    S Anand

Maybe you are looking for

  • Document rows Cannot be closed concurrently - Purchase Orders

    hello, I am trying to close Purchase Orders using DTW. When I import the files I get the following error : Document rows Cannot be closed concurrently with the other document modifications you have made (POR1.linestatus). These are item Purchase Orde

  • Photoshop CC 14.2 Freeze eventually (every 2/5 mins) from the last update.

    Good afternoon, Photoshop CC It freeze  from the last update (14.2) ,the application remains frozen for 1 or 2 min and runs for another 2 mins till refreezes. MOUNTAIN WORKSTATION i7-4930k 32 Gb Ram Win 8 Nvidia GTX - 780 (Updated 332.21 / 2014-7-1)

  • Want to use Time Machine, what do I need to do?

    Looking to free up space on my computer, heard about Time Machine, but, have no clue what it is or how to use it.  Do I really need to use it?

  • Changing Purchase Order

    Hi, I am working on Smartforms (Purchase Order in ECC 6.0 ).My requirement is if we change any Quantity or Delivery Date , in the output it should show Quantity Changed or Delivery Date Changed. But it is not showing .How can we do this? But if we ru

  • Design Studio - Mobile devices compatibilty

    Hi Friends, I need to deploy WEBIreports and Dashboards in mobile devices of different OS like IOS/Android/Windows. How far is it possible to fulfull this requirement through design studio. BO Ver - 4.1 Thanks, Gaurav