Pivot (Crosstab) question

Is there a way to use a function for column or row definition in a pivot (crosstab) table in a RTF template ?
For example, if our data set has a date field, and we want ta pivot table that has columns based on the year of that field, how would we create that pivot table? Accoirding to the BIP documentation, there is a function <?xdoxslt:get_year('2000-04-08', $_XDOLOCALE)?> that returns the year of a date field. Using this in the column definition, gives me a error. ie
changing
<?crosstab:c9827;"//G_1";"PRG_TITLE{PRG_CODE,o=a,t=t}";"PL_DATE{,o=a,t=t}";"AMOUNT";"sum"?>
to
<?crosstab:c9827;"//G_1";"PRG_TITLE{PRG_CODE,o=a,t=t}";"xdoxslt:get_year(PL_DATE,$_XDOLOCALE){,o=a,t=t}";"AMOUNT";"sum"?>
Using the XQuery conversion function year-from-date gives me again an error.
Of course, we could go ahead, and insert the year filed in our data and use it, but what we aiming is a general solution - is one exists .
Thank you

Thanks, again, but no it doesn't. Double-clicking (at least on my computer) merely collapses (or expands) the particular item in the pivot.
Oh, well. This would be a useful (and logical) feature. That is, while in the pivot table, when clicking (double-clicking, whatever), be taken to the original point in the worksheet (for editing purposes). It servers no logical purpose whatsoever to open
a new Worksheet.
It works perfectly OK at this end.
I disagree that it serves no useful purpose: its purpose is to provide a breakdown of the aggregated figure in the pivot and this is something that users often require (the ability to, "drill down" and see how a number is made up).
Go to my website:-
http://www.pierrefondes.com/
 - and open item 201.
It should open to the Worksheet called:-
pivot_chart
Double click in cell:-
B4
 - which has a total of:-
58
 - in it.
A new Worksheet called:-
Sheet1
 - should now open showing you how that:-
58
 - is made up.
Does that help?

Similar Messages

  • Crosstab Question

    Is it possible to do crosstab query in oracle ? Basically, I've got information in this format:
    ShopName userid     Method Sum(Amount_Paid)Count(Amount_paid)
    Shop1      1     Master_Card     400     1
    Shop1      1     Cash     500     2
    Shop1      2     Cash     1300     2
    Shop2     3     Cash     130     1
    Shop2     3     Master Card     900     1
    Shop2     4     Cash     50     1
    & I want to get the information in this format:
    ShopName userid     Sum(Master_Card)Count(Master_Card)
    Sum(Cash)Count(Cash)......
    Shop1      1     400     1 500     2
    Shop1      2     0     0 1300 2
    Shop2     3     900     1 130     1
    Shop2     4     0     0 50     1
    Note that the payment method (cash, master card .....)
    isn't fixed they came from another table

    I beleive that crosstab and pivot table are the same
    where I have family names I am thinking would be your shop1
    job would be master card, cash
    dept would be shop
    Hope this will help you get started
    SQL> break on report
    SQL> compute sum LABEL 'TOTAL' of 'dept_10' on report
    SQL> compute sum of 'dept_20' on report
    SQL> compute sum of 'dept_30' on report
    SQL> compute sum of total on report
    SQL>
    SQL> select job,
    2 max( decode(deptno, 10, SPENT, 0 ) ) dept_10,
    3 max( decode(deptno, 20, SPENT, 0 ) ) dept_20,
    4 max (decode (deptno, 30, SPENT, 0)) dept_30,
    5 max( decode(deptno, 10, SPENT, 0 ) ) +
    6 max( decode(deptno, 20, SPENT, 0 ) ) +
    7 max (decode (deptno, 30, SPENT, 0)) TOTAL
    8 from (select job, deptno, sum(nvl(sal,0)) spent from emp group by job, deptno)
    9 GROUP BY job;
    JOB DEPT_10 DEPT_20 DEPT_30 TOTAL
    ANALYST 0 6000 0 6000
    CLERK 1300 1900 950 4150
    MANAGER 2450 2975 2850 8275
    PRESIDENT 5000 0 0 5000
    SALESMAN 0 0 5600 5600
    TOTAL 8750 10875 9400 29025

  • OBIEE 11g pivot dumb question - changing order of measure columns

    Hi, dumb question, in OBIEE 11g, if using a table view it is easy for end users to drag and drop the measure columns in any order desired. Is there a way for end users to change the order of measures when using a pivot view?
    Thanks,
    Scott

    Hi Dpka, no, moving to rows doesn't really solve the issue. Dimensions don't allow you to change the order of the members, except by alphabetic sort.
    Lets say the default pivot has three measure columns in this order:
    1. Sales
    2. Revenue
    3. Cost of Goods Sold.
    If a user wants to change the order of the columns to be:
    1. Sales
    2. Cost of Goods Sold
    3. Revenue
    on a table they just drag the columns the way they want them. On a pivot, it appears that there is no way to change this.
    Thx,
    Scott

  • CrossTab Questions

    I have a crosstab that looks something like this:
         Jan-08     Feb-08     Mar-08     Apr-08     May-08     Jun-08
    Jan-08     A     B     C     D     E     F
    Feb-08          G     H     I     J     K
    Mar-08               L     M     N     O
    Apr-08                    P     Q     R
    May-08                         S     T
    Jun-08                              U
    There are two things I need to be able to do with this crosstab.  First, I need to be able to paint the diagonals in different colors.  For example, AGLPSU needs to be red, BHMQT needs to be blue, CINR needs to be green, DJO needs to be orange, EK needs to be brown and F needs to be yellow.  There is no specific rule for these colors, just that each object within a diagonal needs to be the same color and each diagonal line needs to be a different color.  In otherwords, the highlighting of each object is based on location and not value.
    The second thing I need is to present a version of this crosstab as a % where AGLPSU are all 100%, B is the % if G, C and H are % of L, DIM are each the % of P, etc.
    I can't figure out how to do either of these, or if it is possible to do either of these.  If not, the client will be forced to export to Excel which frustrates the purpose of the report.
    Fuskie
    Who hopes someone has a positive answer...

    Brilliant.  I never would have thought of this.  I had to put the column total formula into the Horizontal Alignment format property condition since the client wanted column totals suppressed and I extended the color selection to 13 (they run the report for 13 months), but it looks great.  Now if only you could center a cross-tab horizontally on a page.
    Here is a better discription of the second question. Take the following crosstab data:
         Jan-08     Feb-08     Mar-08     Apr-08     May-08     Jun-08
    Jan-08     481     169     139     111     104     95
    Feb-08          506     207     155     131     121
    Mar-08               489     174     132     122
    Apr-08                    388     175     138
    May-08                         475     157
    Jun-08                              426
    I want the second crosstab to look like this:
         Jan-08     Feb-08     Mar-08     Apr-08     May-08     Jun-08
    Jan-08     100%     33%     28%     29%     22%     22%
    Feb-08          100%     42%     40%     28%     28%
    Mar-08               100%     45%     28%     29%
    Apr-08                    100%     37%     32%
    May-08                         100%     37%
    Jun-08                              100%
    For February 08, 33% is 169/506.  For March 08, 28% is 139/489 and 42% is 207/489, etc.  Hope this is more clear.
    Fuskie
    Who is learning to think outside the crosstab...

  • General CROSSTAB question

    Is it possible to create a crosstab report similar to:
    FIELD A-designation(value 1,2 or 3)
    FIELD B-year
    C| data
    D| data
    whereby designation 1 will always have under it both columns with data for the requested year and columns with data for the requested year - 1, while designation with value 2 or 3 will have columns of data only for the requested year?
    From my knowledge I can't see how it is possible to describe it in the layout; I am double-checking if there is a way around it.
    Thank you .
    Leah

    Please disregard this question. I think that it will all work out.
    Thanks to anyone who thought about my question.

  • Pivot query question

    I've a query in Oracle 11:
    select to_char(da,'DY-DD') days
    from (
            select rownum -1 + to_date('2012-10-15','yyyy-mm-dd') da, l
            from   (select level l
                    from   dual  connect by level <= to_date('2012-10-21','yyyy-mm-dd') - to_date('2012-10-15','yyyy-mm-dd')+1)
            order by 1) Result
    "DAYS"
    MON-15
    TUE-16
    WED-17
    THU-18
    FRI-19
    SAT-20
    SUN-21What I need is that the present in a row instead of a column:
    MON-15  TUE-16  WED-17  THU-18  FRI-19  SAT-20  SUN-21This should be done with pivot queries? Any suggestion please!
    Thanks in advance.

    While testing I discoverd that for some days I've more than 1 record for the ending and beginning balance for a day:
    Mon15 Tue16
    BB EB BB EB
    17 19 27 21
    19 27 21 26create statement for the table:
    create table balances(b_date date, begining_balance number(10,2) , ending_balance number(10,2));insert for date:
    begin
      INSERT INTO balances values('15-OCT-2012',17,19);
      INSERT INTO balances values('16-OCT-2012',19,21);
      INSERT INTO balances values('17-OCT-2012',21,8);
      INSERT INTO balances values('18-OCT-2012',8,7);
      INSERT INTO balances values('19-OCT-2012',7,1);
      INSERT INTO balances values('20-OCT-2012',1,17);
      Insert Into Balances Values('21-OCT-2012',17,19);
      Insert Into Balances Values('15-OCT-2012',19,27);
      Insert Into Balances Values('16-OCT-2012',21,26);
      End;
    commit;I I use the min(case.......) clause I only get one balance. I've I remove the min from the clause I get all but also a lot of empty rows:
    WITH     all_dates     AS
         SELECT     LEVEL               AS n
         ,     TO_DATE ( '15-Oct-2012'
                   , 'DD-Mon-YYYY'
                   ) + LEVEL - 1     AS a_date
         FROM     dual
         CONNECT BY     LEVEL     <= 7
    ,     unpivoted_data     AS
         SELECT     a.n
         ,     TO_CHAR (a.a_date, 'DyDD')     AS dydd
         ,     TO_CHAR (b.begining_balance)     AS beginning_balance
         ,     TO_CHAR (b.ending_balance)     AS ending_balance
         FROM     all_dates  a
         JOIN     balances   b  ON  b.b_date  = a.a_date
    SELECT       MIN (CASE WHEN n = 1 THEN dydd END)     AS bb_1
    ,       MIN (CASE WHEN n = 1 THEN dydd END)     AS eb_1
    ,       MIN (CASE WHEN n = 2 THEN dydd END)     AS bb_2
    ,       MIN (CASE WHEN n = 2 THEN dydd END)     AS eb_2
    ,       1                                            AS r_num
    FROM       unpivoted_data
        UNION ALL
    SELECT       'BB'
    ,       'EB'
    ,       'BB'
    ,       'EB'
    ,       2     AS r_num
    FROM       dual
        UNION ALL
    SELECT        (CASE WHEN n = 1 THEN beginning_balance END)
    ,        (CASE WHEN n = 1 THEN ending_balance    END)
    ,        (CASE WHEN n = 2 THEN beginning_balance END)
    ,        (CASE WHEN n = 2 THEN ending_balance    END)
    ,       3   AS r_num
    From       Unpivoted_Dataresult:
    Mon15     Mon15     Tue16     Tue16     1
    BB     EB     BB     EB     2
    17     19               3
              19     21     3
                        3
                        3
                        3
                        3
    19     27               3
              21     26     3is there a way I could ommit the null values in the query? I only want the output as:
    Mon15 Tue16
    BB EB BB EB
    17 19 27 21
    19 27 21 26Thanks in advance!

  • Pivot / Crosstab XML Data....

    Hi,
    Does anyone know how to present an XML datasource into a Crosstab format?
    I've read one document suggesting the use of the SUMIF function - which is novel, but I reckon that's a pretty poor way to have to do it.
    Does anyone have a better method?
    Regards
    Mick

    bump

  • Crosstab view

    Hi,
    Is it possible to change this code to a pivot crosstab ?
    select a.INPATIENTS , d.OUTPATIENTS, (a.INPATIENTS + d.OUTPATIENTS ) TOTAL from
    (select     count(OPAT_OPAT.DOSSIER_NUM) as INPATIENTS
    from     "OPAT_OPAT" "OPAT_OPAT"
    where      "OPAT_OPAT"."IV_ACCESS" IN ('PICC DOUBLE','PICC SIMPLE')
    and     "OPAT_OPAT"."UNIT_ID" IN ('MDH')
    )a ,
    (select     count(OPAT_OPAT.DOSSIER_NUM) as OUTPATIENTS
    from     "OPAT_OPAT" "OPAT_OPAT"
    where      "OPAT_OPAT"."IV_ACCESS" IN ('PICC DOUBLE','PICC SIMPLE')
    and     "OPAT_OPAT"."UNIT_ID" NOT IN ('MDH')
    ) d
    group by a.INPATIENTS , d.OUTPATIENTS
    UNION
    select a.INPATIENTS , d.OUTPATIENTS, (a.INPATIENTS + d.OUTPATIENTS ) TOTAL from
    (select     count(OPAT_OPAT.DOSSIER_NUM) as INPATIENTS
    from     "OPAT_OPAT" "OPAT_OPAT"
    where      "OPAT_OPAT"."IV_ACCESS" IN ('NS Lock')
    and     "OPAT_OPAT"."UNIT_ID" IN ('MDH')
    )a ,
    (select     count(OPAT_OPAT.DOSSIER_NUM) as OUTPATIENTS
    from     "OPAT_OPAT" "OPAT_OPAT"
    where      "OPAT_OPAT"."IV_ACCESS" IN ('NS Lock')
    and     "OPAT_OPAT"."UNIT_ID" NOT IN ('MDH')
    ) d
    group by a.INPATIENTS , d.OUTPATIENTS
    UNION
    select a.INPATIENTS , d.OUTPATIENTS, (a.INPATIENTS + d.OUTPATIENTS ) TOTAL from
    (select     count(OPAT_OPAT.DOSSIER_NUM) as INPATIENTS
    from     "OPAT_OPAT" "OPAT_OPAT"
    where      "OPAT_OPAT"."IV_ACCESS" IN ('TUNNELED')
    and     "OPAT_OPAT"."UNIT_ID" IN ('MDH')
    )a ,
    (select     count(OPAT_OPAT.DOSSIER_NUM) as OUTPATIENTS
    from     "OPAT_OPAT" "OPAT_OPAT"
    where      "OPAT_OPAT"."IV_ACCESS" IN ('TUNNELED')
    and     "OPAT_OPAT"."UNIT_ID" NOT IN ('MDH')
    ) d
    group by a.INPATIENTS , d.OUTPATIENTS
    UNION
    select a.INPATIENTS , d.OUTPATIENTS, (a.INPATIENTS + d.OUTPATIENTS ) TOTAL from
    (select     count(OPAT_OPAT.DOSSIER_NUM) as INPATIENTS
    from     "OPAT_OPAT" "OPAT_OPAT"
    where      "OPAT_OPAT"."IV_ACCESS" IN ('PORT')
    and     "OPAT_OPAT"."UNIT_ID" IN ('MDH')
    )a ,
    (select     count(OPAT_OPAT.DOSSIER_NUM) as OUTPATIENTS
    from     "OPAT_OPAT" "OPAT_OPAT"
    where      "OPAT_OPAT"."IV_ACCESS" IN ('PORT')
    and     "OPAT_OPAT"."UNIT_ID" NOT IN ('MDH')
    ) d
    group by a.INPATIENTS , d.OUTPATIENTS
    Thank you. Eric

    Hi,
    Im now facing a similiar requirement. Can you please share with me how you can achieved that using ADF.
    Regards
    Mohan

  • Report from PL/SQL

    Hi guys,
    I'm using BI Publisher - a tool for generating reports using SQL queries - to create some reports.
    Since I'm not an expert in SQL I'm here to ask for some help.
    I have a table which maps products to packages.
    For example, suppose that "Package A" has tree products into it then in this table there would exist three rows for "Package A", each one holding a product code.
    I want to generate a report that would list in one column all products and the other columns would be dynamic holding the distinct amount of packages found in this table.
    The final report would be like this:
    PRODUCT     PACKAGE A     PACKAGE B     ...     PACKAGE C
    PRODUCT A                    X
    PRODUCT B     X     X          X
    PRODUCT C          X          X
    PRODUCT D                    X
    How can I achieve that?
    Best regards,
    Caio

    908832 wrote: ... Etc ...
    How can I achieve that?
    By searching the forum for "pivot", "crosstab" or "rows to columns" postings.
    :p

  • PL/SQL 101 : Cursors and SQL Projection

    PL/SQL 101 : Cursors and SQL Projection
    This is not a question, it's a forum article, in reponse to the number of questions we get regarding a "dynamic number of columns" or "rows to columns"
    There are two integral parts to an SQL Select statement that relate to what data is selected. One is Projection and the other is Selection:-
    Selection is the one that we always recognise and use as it forms the WHERE clause of the select statement, and hence selects which rows of data are queried.
    The other, SQL Projection is the one that is less understood, and the one that this article will help to explain.
    In short, SQL Projection is the collective name for the columns that are Selected and returned from a query.
    So what? Big deal eh? Why do we need to know this?
    The reason for knowing this is that many people are not aware of when SQL projection comes into play when you issue a select statement. So let's take a basic query...
    First create some test data...
    create table proj_test as
      select 1 as id, 1 as rn, 'Fred' as nm from dual union all
      select 1,2,'Bloggs' from dual union all
      select 2,1,'Scott' from dual union all
      select 2,2,'Smith' from dual union all
      select 3,1,'Jim' from dual union all
      select 3,2,'Jones' from dual
    ... and now query that data...
    SQL> select * from proj_test;
             ID         RN NM
             1          1 Fred
             1          2 Bloggs
             2          1 Scott
             2          2 Smith
             3          1 Jim
             3          2 Jones
    6 rows selected.
    OK, so what is that query actually doing?
    To know that we need to consider that all queries are cursors and all cursors are processed in a set manner, roughly speaking...
    1. The cursor is opened
    2. The query is parsed
    3. The query is described to know the projection (what columns are going to be returned, names, datatypes etc.)
    4. Bind variables are bound in
    5. The query is executed to apply the selection and identify the data to be retrieved
    6. A row of data is fetched
    7. The data values from the columns within that row are extracted into the known projection
    8. Step 6 and 7 are repeated until there is no more data or another condition ceases the fetching
    9. The cursor is closed
    The purpose of the projection being determined is so that the internal processing of the cursor can allocate memory etc. ready to fetch the data into. We won't get to see that memory allocation happening easily, but we can see the same query being executed in these steps if we do it programatically using the dbms_sql package...
    CREATE OR REPLACE PROCEDURE process_cursor (p_query in varchar2) IS
      v_sql       varchar2(32767) := p_query;
      v_cursor    number;            -- A cursor is a handle (numeric identifier) to the query
      col_cnt     integer;
      v_n_val     number;            -- numeric type to fetch data into
      v_v_val     varchar2(20);      -- varchar type to fetch data into
      v_d_val     date;              -- date type to fetch data into
      rec_tab     dbms_sql.desc_tab; -- table structure to hold sql projection info
      dummy       number;
      v_ret       number;            -- number of rows returned
      v_finaltxt  varchar2(100);
      col_num     number;
    BEGIN
      -- 1. Open the cursor
      dbms_output.put_line('1 - Opening Cursor');
      v_cursor := dbms_sql.open_cursor;
      -- 2. Parse the cursor
      dbms_output.put_line('2 - Parsing the query');
      dbms_sql.parse(v_cursor, v_sql, dbms_sql.NATIVE);
      -- 3. Describe the query
      -- Note: The query has been described internally when it was parsed, but we can look at
      --       that description...
      -- Fetch the description into a structure we can read, returning the count of columns that has been projected
      dbms_output.put_line('3 - Describing the query');
      dbms_sql.describe_columns(v_cursor, col_cnt, rec_tab);
      -- Use that description to define local datatypes into which we want to fetch our values
      -- Note: This only defines the types, it doesn't fetch any data and whilst we can also
      --       determine the size of the columns we'll just use some fixed sizes for this example
      dbms_output.put_line(chr(10)||'3a - SQL Projection:-');
      for j in 1..col_cnt
      loop
        v_finaltxt := 'Column Name: '||rpad(upper(rec_tab(j).col_name),30,' ');
        case rec_tab(j).col_type
          -- if the type of column is varchar2, bind that to our varchar2 variable
          when 1 then
            dbms_sql.define_column(v_cursor,j,v_v_val,20);
            v_finaltxt := v_finaltxt||' Datatype: Varchar2';
          -- if the type of the column is number, bind that to our number variable
          when 2 then
            dbms_sql.define_column(v_cursor,j,v_n_val);
            v_finaltxt := v_finaltxt||' Datatype: Number';
          -- if the type of the column is date, bind that to our date variable
          when 12 then
            dbms_sql.define_column(v_cursor,j,v_d_val);
            v_finaltxt := v_finaltxt||' Datatype: Date';
          -- ...Other types can be added as necessary...
        else
          -- All other types we'll assume are varchar2 compatible (implicitly converted)
          dbms_sql.DEFINE_COLUMN(v_cursor,j,v_v_val,2000);
          v_finaltxt := v_finaltxt||' Datatype: Varchar2 (implicit)';
        end case;
        dbms_output.put_line(v_finaltxt);
      end loop;
      -- 4. Bind variables
      dbms_output.put_line(chr(10)||'4 - Binding in values');
      null; -- we have no values to bind in for our test
      -- 5. Execute the query to make it identify the data on the database (Selection)
      -- Note: This doesn't fetch any data, it just identifies what data is required.
      dbms_output.put_line('5 - Executing the query');
      dummy := dbms_sql.execute(v_cursor);
      -- 6.,7.,8. Fetch the rows of data...
      dbms_output.put_line(chr(10)||'6,7 and 8 Fetching Data:-');
      loop
        -- 6. Fetch next row of data
        v_ret := dbms_sql.fetch_rows(v_cursor);
        -- If the fetch returned no row then exit the loop
        exit when v_ret = 0;
        -- 7. Extract the values from the row
        v_finaltxt := null;
        -- loop through each of the Projected columns
        for j in 1..col_cnt
        loop
          case rec_tab(j).col_type
            -- if it's a varchar2 column
            when 1 then
              -- read the value into our varchar2 variable
              dbms_sql.column_value(v_cursor,j,v_v_val);
              v_finaltxt := ltrim(v_finaltxt||','||rpad(v_v_val,20,' '),',');
            -- if it's a number column
            when 2 then
              -- read the value into our number variable
              dbms_sql.column_value(v_cursor,j,v_n_val);
              v_finaltxt := ltrim(v_finaltxt||','||to_char(v_n_val,'fm999999'),',');
            -- if it's a date column
            when 12 then
              -- read the value into our date variable
              dbms_sql.column_value(v_cursor,j,v_d_val);
              v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          else
            -- read the value into our varchar2 variable (assumes it can be implicitly converted)
            dbms_sql.column_value(v_cursor,j,v_v_val);
            v_finaltxt := ltrim(v_finaltxt||',"'||rpad(v_v_val,20,' ')||'"',',');
          end case;
        end loop;
        dbms_output.put_line(v_finaltxt);
        -- 8. Loop to fetch next row
      end loop;
      -- 9. Close the cursor
      dbms_output.put_line(chr(10)||'9 - Closing the cursor');
      dbms_sql.close_cursor(v_cursor);
    END;
    SQL> exec process_cursor('select * from proj_test');
    1 - Opening Cursor
    2 - Parsing the query
    3 - Describing the query
    3a - SQL Projection:-
    Column Name: ID                             Datatype: Number
    Column Name: RN                             Datatype: Number
    Column Name: NM                             Datatype: Varchar2
    4 - Binding in values
    5 - Executing the query
    6,7 and 8 Fetching Data:-
    1     ,1     ,Fred
    1     ,2     ,Bloggs
    2     ,1     ,Scott
    2     ,2     ,Smith
    3     ,1     ,Jim
    3     ,2     ,Jones
    1     ,3     ,Freddy
    1     ,4     ,Fud
    9 - Closing the cursor
    PL/SQL procedure successfully completed.
    So, what's really the point in knowing when SQL Projection occurs in a query?
    Well, we get many questions asking "How do I convert rows to columns?" (otherwise known as a pivot) or questions like "How can I get the data back from a dynamic query with different columns?"
    Let's look at a regular pivot. We would normally do something like...
    SQL> select id
      2        ,max(decode(rn,1,nm)) as nm_1
      3        ,max(decode(rn,2,nm)) as nm_2
      4  from proj_test
      5  group by id
      6  /
            ID NM_1   NM_2
             1 Fred   Bloggs
             2 Scott  Smith
             3 Jim    Jones
    (or, in 11g, use the new PIVOT statement)
    but many of these questioners don't understand it when they say their issue is that, they have an unknown number of rows and don't know how many columns it will have, and they are told that you can't do that in a single SQL statement. e.g.
    SQL> insert into proj_test (id, rn, nm) values (1,3,'Freddy');
    1 row created.
    SQL> select id
      2        ,max(decode(rn,1,nm)) as nm_1
      3        ,max(decode(rn,2,nm)) as nm_2
      4  from proj_test
      5  group by id
      6  /
            ID NM_1   NM_2
             1 Fred   Bloggs
             2 Scott  Smith
             3 Jim    Jones
    ... it's not giving us this 3rd entry as a new column and we can only get that by writing the expected columns into the query, but then what if more columns are added after that etc.
    If we look back at the steps of a cursor we see again that the description and projection of what columns are returned by a query happens before any data is fetched back.
    Because of this, it's not possible to have the query return back a number of columns that are based on the data itself, as no data has been fetched at the point the projection is required.
    So, what is the answer to getting an unknown number of columns in the output?
    1) The most obvious answer is, don't use SQL to try and pivot your data. Pivoting of data is more of a reporting requirement and most reporting tools include the ability to pivot data either as part of the initial report generation or on-the-fly at the users request. The main point about using the reporting tools is that they query the data first and then the pivoting is simply a case of manipulating the display of those results, which can be dynamically determined by the reporting tool based on what data there is.
    2) The other answer is to write dynamic SQL. Because you're not going to know the number of columns, this isn't just a simple case of building up a SQL query as a string and passing it to the EXECUTE IMMEDIATE command within PL/SQL, because you won't have a suitable structure to read the results back into as those structures must have a known number of variables for each of the columns at design time, before the data is know. As such, inside PL/SQL code, you would have to use the DBMS_SQL package, just like in the code above that showed the workings of a cursor, as the columns there are referenced by position rather than name, and you have to deal with each column seperately. What you do with each column is up to you... store them in an array/collection, process them as you get them, or whatever. They key thing though with doing this is that, just like the reporting tools, you would need to process the data first to determine what your SQL projection is, before you execute the query to fetch the data in the format you want e.g.
    create or replace procedure dyn_pivot is
      v_sql varchar2(32767);
      -- cursor to find out the maximum number of projected columns required
      -- by looking at the data
      cursor cur_proj_test is
        select distinct rn
        from   proj_test
        order by rn;
    begin
      v_sql := 'select id';
      for i in cur_proj_test
      loop
        -- dynamically add to the projection for the query
        v_sql := v_sql||',max(decode(rn,'||i.rn||',nm)) as nm_'||i.rn;
      end loop;
      v_sql := v_sql||' from proj_test group by id order by id';
      dbms_output.put_line('Dynamic SQL Statement:-'||chr(10)||v_sql||chr(10)||chr(10));
      -- call our DBMS_SQL procedure to process the query with it's dynamic projection
      process_cursor(v_sql);
    end;
    SQL> exec dyn_pivot;
    Dynamic SQL Statement:-
    select id,max(decode(rn,1,nm)) as nm_1,max(decode(rn,2,nm)) as nm_2,max(decode(rn,3,nm)) as nm_3 from proj_test group by id order by id
    1 - Opening Cursor
    2 - Parsing the query
    3 - Describing the query
    3a - SQL Projection:-
    Column Name: ID                             Datatype: Number
    Column Name: NM_1                           Datatype: Varchar2
    Column Name: NM_2                           Datatype: Varchar2
    Column Name: NM_3                           Datatype: Varchar2
    4 - Binding in values
    5 - Executing the query
    6,7 and 8 Fetching Data:-
    1     ,Fred                ,Bloggs              ,Freddy
    2     ,Scott               ,Smith               ,
    3     ,Jim                 ,Jones               ,
    9 - Closing the cursor
    PL/SQL procedure successfully completed.
    ... and if more data is added ...
    SQL> insert into proj_test (id, rn, nm) values (1,4,'Fud');
    1 row created.
    SQL> exec dyn_pivot;
    Dynamic SQL Statement:-
    select id,max(decode(rn,1,nm)) as nm_1,max(decode(rn,2,nm)) as nm_2,max(decode(rn,3,nm)) as nm_3,max(decode(rn,4,nm)) as nm_4 from proj_test group by id order by id
    1 - Opening Cursor
    2 - Parsing the query
    3 - Describing the query
    3a - SQL Projection:-
    Column Name: ID                             Datatype: Number
    Column Name: NM_1                           Datatype: Varchar2
    Column Name: NM_2                           Datatype: Varchar2
    Column Name: NM_3                           Datatype: Varchar2
    Column Name: NM_4                           Datatype: Varchar2
    4 - Binding in values
    5 - Executing the query
    6,7 and 8 Fetching Data:-
    1     ,Fred                ,Bloggs              ,Freddy              ,Fud
    2     ,Scott               ,Smith               ,                    ,
    3     ,Jim                 ,Jones               ,                    ,
    9 - Closing the cursor
    PL/SQL procedure successfully completed.
    Of course there are other methods, using dynamically generated scripts etc. (see Re: 4. How do I convert rows to columns?), but the above simply demonstrates that:-
    a) having a dynamic projection requires two passes of the data; one to dynamically generate the query and another to actually query the data,
    b) it is not a good idea in most cases as it requires code to handle the results dynamically rather than being able to simply query directly into a known structure or variables, and
    c) a simple SQL statement cannot have a dynamic projection.
    Most importantly, dynamic queries prevent validation of your queries at the time your code is compiled, so the compiler can't check that the column names are correct or the tables names, or that the actual syntax of the generated query is correct. This only happens at run-time, and depending upon the complexity of your dynamic query, some problems may only be experienced under certain conditions. In effect you are writing queries that are harder to validate and could potentially have bugs in them that would are not apparent until they get to a run time environment. Dynamic queries can also introduce the possibility of SQL injection (a potential security risk), especially if a user is supplying a string value into the query from an interface.
    To summarise:-
    The projection of an SQL statement must be known by the SQL engine before any data is fetched, so don't expect SQL to magically create columns on-the-fly based on the data it's retrieving back; and, if you find yourself thinking of using dynamic SQL to get around it, just take a step back and see if what you are trying to achieve may be better done elsewhere, such as in a reporting tool or the user interface.
    Other articles in the PL/SQL 101 series:-
    PL/SQL 101 : Understanding Ref Cursors
    PL/SQL 101 : Exception Handling

    excellent article. However there is one thing which is slightly erroneous. You don't need a type to be declared in the database to fetch the data, but you do need to declare a type;
    here is one of my unit test scripts that does just that.
    DECLARE
    PN_CARDAPPL_ID NUMBER;
    v_Return Cci_Standard.ref_cursor;
    type getcardapplattrval_recordtype
    Is record
    (cardappl_id ci_cardapplattrvalue.cardappl_ID%TYPE,
    tag ci_cardapplattrvalue.tag%TYPE,
    value ci_cardapplattrvalue.value%TYPE
    getcardapplattrvalue_record getcardapplattrval_recordtype;
    BEGIN
    PN_CARDAPPL_ID := 1; --value must be supplied
    v_Return := CCI_GETCUSTCARD.GETCARDAPPLATTRVALUE(
    PN_CARDAPPL_ID => PN_CARDAPPL_ID
    loop
    fetch v_return
    into getcardapplattrvalue_record;
    dbms_output.put_line('Cardappl_id=>'||getcardapplattrvalue_record.cardappl_id);
    dbms_output.put_line('Tag =>'||getcardapplattrvalue_record.tag);
    dbms_output.put_line('Value =>'||getcardapplattrvalue_record.value);
    exit when v_Return%NOTFOUND;
    end loop;
    END;

  • Printer Dialog Box in CS4 - Printing Grayscale Images

    I hope I'm not duplicating a new topic. I thought I opened this topic yesterday but I don't seem to be able to locate it in this forum. So, I'll try again. This is a pivotal CS4 question re printer set-up for grayscale images with and without b&w profiles.
    When setting up print parameters for a Grayscale image in PS CS4 I no longer have the option to select "No Color Management." It seems to be available to RGB images but not grayscale. Which leads to the question as to how I set up print parameters to print grayscale images using Advanced Black & White mode. Can you help?
    Regards,
    King Dexter

    As it turns out my original problem has led into a more serious set of color management changes found in CS4. In my case, for instance, I'm finding it difficult to determine the correct way to print untagged, ABW grayscale profiling targets. Others are having similar difficulties with color profiling. Other forums are buzzing as people migrate to PSCS4: Here are just a few examples that hopefully will attract Adobe attention here:
    Excerpt #1:
    Sounds like this should be raised in the PS forums where Chris Cox
    will pick it up. (I raised the colour mgt issues of Bridge there and
    they picked that up.)
    Excerpt #2:
    The deeper explanation going on here has to do with printing interfaces on OS X changing over time. In the past, some printer drivers (notably Canon, with its older iPF series printers) did not interpret the image data appropriately and thus had incorrect driver settings that could not be reset by the user. Photoshop CS3 worked around some of these issues for specific drivers, but did not conform to Apple's OS X specifications for how to pass image data to the print driver, leading to problems elsewhere. With CS4, Adobe has taken the approach of conforming to Apple's latest print driver interface specifications, so CS4 now has the same behavior as LR with regards to printing on OS X.
    However, many print drivers have not been updated to conform to the OS X printing interface, and thus some folks are experiencing printing issues, such as double color-management. This is unfortunate, but it really needs to be addressed by the printer drivers.
    Now, back to the ABW situation: I don't know if Epson has a glitch with the ABW driver under the latest OS X release. I have occasionally seen what you've seen: i.e., I hit "Print" in PS CS4 and nothing comes out. But then I mess around a little with the Epson printer driver configuration and then it works.
    In particular, I found that if I had an older "saved setting" or preset within the Epson driver that I used to recall a particular ABW driver setting, then it would fail. So I deleted all my Epson driver presets and started again from scratch (manually selecting media type, color mode, ABW settings, paper config, etc.) Then I haven't had any trouble printing ABW images since.
    Excerpt #3
    I've done some testing of various color management approaches and it is indeed
    confusing.
    Here's what I've deduced using CS3 and CS4 with drivers printing stepwedges.
    CS3 with No Color Mgmt I consider the "correct" result. The driver gets 21
    evenly stepped values.
    With CS4, only Photoshop Manages Color with Print Profile = Working Gray Space
    gives the identical results. (assuming grayscale, untagged file).
    Printer Manages Color makes a default conversion to Generic Gray Profile which
    is a gamma 1.8 profile. If you happen to use GG 1.8 as a working space this conversion may not hurt but if you use GG 2.2 it'll darken the print. I think this has been true in PS for
    several versions.
    To make things more complicated OS X 10.5 has a new print dialog pane called
    Color Matching which allows you to select Colorsync vs driver based mode and ICC profiles. I
    don't know how this will affect things -- I'd leave it alone.
    No Color Management is selectable with an RGB file but I just got blank pages
    with this option.
    -- QTR definitely received a blank page from the system. This is probably
    related to your
    ABW printing not working.
    Note that the CS4 documentation specifically states to use No CM for making
    custom ICC profiles.

  • Question Regarding Crosstab or Matrix Reporting

    Hi,
    I have a Requirement Where I have to Create a Cross-tab Report,
    We use XMLPublisher which is Bundled with R12...
    our ERP version is :12.1.3
    Our XML Publisher is :5.6.3.x.x
    The Requirement Output is
    I have Generate a report which should be a Pivot Report for Every item Entered by the User (it may be one or Multiple Item)
    if one Item is Entered
    I have To list the report as below
    ITEM ID:1234 ITEM DESC: SquarePaper Plate =>Item Detail to be printed on top of the table.. Followed by
    DATE is the Column field for the Crosstab
    ORDER STATUS  is the Row Field( Order Status will be of Five Types( BOOKED,ENTERED,AWAITING_SHIPPING,AWAITING_SHIPPING,SHIPPED,CLOSED) for the Crosstab
    QTY is the Field Data Field  for the Row Field(Order Status)..for the Crosstab
    If More than One Entered
    Then I have to Repeat the Same Logic to Produce Pivot Table for that many Items entered by the User..
    For Cross Tab I have Found this Link by Vetsrini
    http://winrichman.blogspot.com/2008/08/pivot-table-cross-table-with-fixed.html
    I followed his Template and I am Getting the Crosstab Output but I am getting for all the Items as One report,
    I could not get a Logic to Group or ( Repeating Group) by Item and Item Description..
    Please help as I am Stuck at this Logic for almost 3 weeks and I have posted so 4-5 questions on this regards unfortunately No replies..
    Thanks

    Hi, Nagornyi,
    Thanks for the Reply,
    <?if:count(ITEM)=1?>
    CROSSTAB_1
    <?end if?>
    <?if:count(ITEM)>1?>
    CROSSTAB_2
    <?end if?>
    When I use this Method, I am getting this Error..
    ConfFile: C:\Program Files\Oracle\BI Publisher\BI Publisher Desktop\Template Builder for Word\config\xdoconfig.xml
    Font Dir: C:\Program Files\Oracle\BI Publisher\BI Publisher Desktop\Template Builder for Word\fonts
    Run XDO Start
    Template: C:\Documents and Settings\aranganathan\Desktop\Currently Working\RTF\tpc_item_count_sum_ver6_test.rtf
    RTFProcessor setLocale: en-us
    FOProcessor setData: C:\Documents and Settings\aranganathan\Desktop\cross_tab_test\tpc_item_count_sample2.xml
    FOProcessor setLocale: en-us
    Output type: MHTML
    java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at oracle.apps.xdo.common.xml.XSLT10gR1.invokeNewXSLStylesheet(Unknown Source)
         at oracle.apps.xdo.common.xml.XSLT10gR1.transform(Unknown Source)
         at oracle.apps.xdo.common.xml.XSLT10gR1.transform(Unknown Source)
         at oracle.apps.xdo.common.xml.XSLTWrapper.transform(Unknown Source)
         at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(Unknown Source)
         at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(Unknown Source)
         at oracle.apps.xdo.template.FOProcessor.createFO(Unknown Source)
         at oracle.apps.xdo.template.FOProcessor.generate(Unknown Source)
         at RTF2PDF.runRTFto(RTF2PDF.java:629)
         at RTF2PDF.runXDO(RTF2PDF.java:470)
         at RTF2PDF.main(RTF2PDF.java:289)
    Caused by: oracle.xdo.parser.v2.XPathException: Error in expression: './/=1'.
         at oracle.xdo.parser.v2.XSLProcessor.reportException(XSLProcessor.java:806)
         at oracle.xdo.parser.v2.XSLProcessor.newXSLStylesheet(XSLProcessor.java:614)
         ... 15 more
    Also
    My Question was
    For Every ITEM_ID entered by the User, I have to Create Crosstab result grouped by ITEM_ID's
    Say
    if the User Enters one ITEM_ID then
    I should Create the Report as
    ITEM ID : 1234 ITEM_DESC: SQUARE PAPER PLATE -- Heading
    CROSSTAB - Report result under the ITEM_ID, and ITEM_DESC
    Say if the ITEM is more than ONE
    ITEM ID : 1234 ITEM_DESC: SQUARE PAPER PLATE -- Heading
    CROSSTAB - Report result under the ITEM_ID, and ITEM_DESC
    ITEM ID : 2341 ITEM_DESC: ROUND PAPER PLATE -- Heading
    CROSSTAB - Report result under the ITEM_ID, and ITEM_DESC
    ITEM ID : 3421 ITEM_DESC: RECTANGULAR PAPER PLATE -- Heading
    CROSSTAB - Report result under the ITEM_ID, and ITEM_DESC
    ITEM ID : 4123 ITEM_DESC: TRANGULAR PAPER PLATE -- Heading
    CROSSTAB - Report result under the ITEM_ID, and ITEM_DESC
    Thanks
    once again

  • How to Unpivot, Crosstab, or Pivot using Oracle 9i with PL/SQL?

    How to Unpivot, Crosstab, or Pivot using Oracle 9i with PL/SQL?
    Here is a fictional sample layout of the data I have from My_Source_Query:
    Customer | VIN | Year | Make | Odometer | ... followed by 350 more columns/fields
    123 | 321XYZ | 2012 | Honda | 1900 |
    123 | 432ABC | 2012 | Toyota | 2300 |
    456 | 999PDQ | 2000 | Ford | 45586 |
    876 | 888QWE | 2010 | Mercedes | 38332 |
    ... followed by up to 25 more rows of data from this query.
    The exact number of records returned by My_Source_Query is unknown ahead of time, but should be less than 25 even under extreme situations.
    Here is how I would like the data to be:
    Column1 |Column2 |Column3 |Column4 |Column5 |
    Customer | 123 | 123 | 456 | 876 |
    VIN | 321XYZ | 432ABC | 999PDQ | 888QWE |
    Year | 2012 | 2012 | 2000 | 2010 |
    Make | Honda | Toyota | Ford | Mercedes|
    Odometer | 1900 | 2300 | 45586 | 38332 |
    ... followed by 350 more rows with the names of the columns/fields from the My_Source_Query.
    From reading and trying many, many, many of the posting on this topic I understand that the unknown number or rows in My_Source_Query can be a problem and have considered working with one row at a time until each row has been converted to a column.
    If possible I'd like to find a way of doing this conversion from rows to columns using a query instead of scripts if that is possible. I am a novice at this so any help is welcome.
    This is a repost. I originally posted this question to the wrong forum. Sorry about that.

    The permission level that I have in the Oracle environment is 'read only'. This is also be the permission level of the users of the query I am trying to build.
    As requested, here is the 'create' SQL to build a simple table that has the type of data I am working with.
    My real select query will have more than 350 columns and the rows returned will be 25 rows of less, but for now I am prototyping with just seven columns that have the different data types noted in my sample data.
    NOTE: This SQL has been written and tested in MS Access since I do not have permission to create and populate a table in the Oracle environment and ODBC connections are not allowed.
    CREATE TABLE tbl_MyDataSource
    (Customer char(50),
    VIN char(50),
    Year char(50),
    Make char(50),
    Odometer long,
    InvDate date,
    Amount currency)
    Here is the 'insert into' to populate the tbl_MyDataSource table with four sample records.
    INSERT INTO tbl_MyDataSource ( Customer, VIN, [Year], Make, Odometer, InvDate, Amount )
    SELECT "123", "321XYZ", "2012", "Honda", "1900", "2/15/2012", "987";
    INSERT INTO tbl_MyDataSource ( Customer, VIN, [Year], Make, Odometer, InvDate, Amount )
    VALUES ("123", "432ABC", "2012", "Toyota", "2300", "1/10/2012", "6546");
    INSERT INTO tbl_MyDataSource ( Customer, VIN, [Year], Make, Odometer, InvDate, Amount )
    VALUES ("456", "999PDQ", "2000", "Ford", "45586", "4/25/2002", "456");
    INSERT INTO tbl_MyDataSource ( Customer, VIN, [Year], Make, Odometer, InvDate, Amount )
    VALUES ("876", "888QWE", "2010", "Mercedes", "38332", "10/13/2010", "15973");
    Which should produce a table containing these columns with these values:
    tbl_MyDataSource:
    Customer     VIN     Year     Make     Odometer     InvDate          Amount
    123 | 321XYZ | 2012 | Honda      | 1900          | 2/15/2012     | 987.00
    123 | 432ABC | 2012 | Toyota | 2300 | 1/10/2012     | 6,546.00
    456 | 999PDQ | 2000 | Ford     | 45586          | 4/25/2002     | 456.00
    876 | 888QWE | 2010 | Mercedes | 38332          | 10/13/2010     | 15,973.00
    The desired result is to use Oracle 9i to convert the columns into rows using sql without using any scripts if possible.
    qsel_MyResults:
    Column1          Column2          Column3          Column4          Column5
    Customer | 123 | 123 | 456 | 876
    VIN | 321XYZ | 432ABC | 999PDQ | 888QWE
    Year | 2012 | 2012 | 2000 | 2010
    Make | Honda | Toyota | Ford | Mercedes
    Odometer | 1900 | 2300 | 45586 | 38332
    InvDate | 2/15/2012 | 1/10/2012 | 4/25/2002 | 10/13/2010
    Amount | 987.00 | 6,546.00 | 456.00 | 15,973.00
    The syntax in SQL is something I am not yet sure of.
    You said:
    >
    "Don't use the same name or alias for two different things. if you have a table called t, then don't use t as an alais for an in-line view. Pick a different name, like ordered_t, instead.">
    but I'm not clear on which part of the SQL you are suggesting I change. The code I posted is something I pieced together from some of the other postings and is not something I full understand the syntax of.
    Here is my latest (failed) attempt at this.
    select *
      from (select * from tbl_MyDataSource) t;
    with data as
    (select rownum rnum, t.* from (select * from t order by c1) ordered_t), -- changed 't' to 'ordered_t'
    rows_to_have as
    (select level rr from dual connect by level <= 7 -- number of columns in T
    select rnum,
           max(decode(rr, 1, c1)),
           max(decode(rr, 2, c2)),
           max(decode(rr, 3, c3)),
           max(decode(rr, 4, c3)),      
           max(decode(rr, 5, c3)),      
           max(decode(rr, 6, c3)),      
           max(decode(rr, 7, c3)),       
      from data, rows_to_have
    group by rnumIn the above code the "select * from tbl_MyDataSource" is a place holder for my select query which runs without error and has these exact number of fields and data types as order shown in the tbl_MyDataSource above.
    This code produces the error 'ORA-00936: missing expression'. The error appears to be starting with the 'with data as' line if I am reading my PL/Sql window correctly. Everything above that row runs without error.
    Thank you for your great patients and for sharing your considerable depth of knowledge. Any help is gratefully welcomed.

  • Really working Crosstab / Pivot Report example

    try it here:
    http://apex.oracle.com/pls/otn/f?p=20819:2
    Details:
    Create Report - based on PL/SQL ************************************
    DECLARE
    l_return_value VARCHAR2(32000) DEFAULT NULL;
    BEGIN
    l_return_value := PK_PIVOT.PivotSQL('SELECT * FROM TESTDATA', 'country,city,product','FDate', 'SUM', 'amount', nvl(:P2_PAGENUMBER,1) );
    --:P2_PAGENUMBER - Textbox above the report
    RETURN l_return_value;
    END;
    Create Supporting PACKAGE PK_PIVOT ************************************
    create or replace
    PACKAGE PK_PIVOT
    --AUTHID CURRENT_USER
    as
    --code based on famous Tom Kyte's books examples
    --but not copy-pasted from there
    type refcursor is ref cursor;
    type array is table of varchar2(30);
    type array_varchar2 is table of varchar2(255);
    Function PivotSQL (
    p_query in varchar2, --query string which returns data you want to make crosstab on
    p_rowfields in varchar2, --row fields separated by comma
    p_columnfield in varchar2, --one column field
    p_function in varchar2,--aggregate function ('SUM','AVG','COUNT','MIN','MAX')
    p_functionfield in varchar2 --field for aggregate function
    , p_page in number default 1--page from right to left (not all columns can be shown on one page)
    ) return varchar2; --returns query text for crosstab
    example:
    SELECT PK_CROSSTAB.PivotSQL('SELECT * FROM scott.emp','empno','job','sum','sal') FROM SYS.DUAL
    SELECT deptno
    ,sum(DECODE(job,'BOSS',sal,null)) as BOSS
    ,sum(DECODE(job,'FIN',sal,null)) as FIN
    ,sum(DECODE(job,'HR',sal,null)) as HR
    ,sum(DECODE(job,'Sales',sal,null)) as Sales
    FROM (SELECT * FROM scott.emp)
    GROUP BY deptno
    ORDER BY deptno
    end;
    create or replace PACKAGE BODY PK_PIVOT as
    Procedure FormatParam (var_data in varchar2, var_type in number, out_decode in out varchar2, out_col in out varchar2);
    Function PivotSQL (
    p_query in varchar2,--
    p_rowfields in varchar2,
    p_columnfield in varchar2,
    p_function in varchar2,
    p_functionfield in varchar2,
    p_page in number default 1
    ) return varchar2
    as
    l_max_cols number;
    l_query long;
    l_columnnames array_varchar2 :=array_varchar2();
    l_cursor refcursor;
    tmp long;
    --dbms_sql types:
    l_theCursor integer default dbms_sql.open_cursor;--get col types
    l_colCnt number default 0;
    l_descTbl dbms_sql.desc_tab;
    col_num number;
    l_columnfieldtype number;
    --decode names   
    o_decode varchar2(50);
    o_col varchar2(50);
    l_cols_per_page number := 50;
    l_begcol number;
    l_endcol number;
    begin
    --check params
    IF instr(p_columnfield,',')>0 THEN
    raise_application_error (-20001, 'Can use only 1 columnfield');
    ELSIF upper(p_function) not in ('SUM','AVG','COUNT','MIN','MAX') THEN
    raise_application_error (-20001, 'Can use only standard aggregate functions');
    END IF;
    /* analyse query */
    dbms_sql.parse(l_theCursor, p_query, dbms_sql.native);
    /* get described columns for analysed query */
    dbms_sql.describe_columns(l_theCursor, l_colCnt, l_descTbl);
    /* Tom Kyte:
    * Following loop could simply be for j in 1..col_cnt loop.
    * Here we are simply illustrating some of the PL/SQL table
    * features.
    col_num := l_descTbl.first;
    loop
    exit when (col_num is null);
    --find column field type
    if l_descTbl(col_num).col_name=upper(p_columnfield) then
    l_columnfieldtype:=l_descTbl(col_num).col_type;
    --dbms_output.put_line('Col#:'||col_num||' Name:'||l_descTbl(col_num).col_name||' Type:'||l_descTbl(col_num).col_type);
    end if;
    col_num := l_descTbl.next(col_num);
    end loop;
    --return 'test ok';
    -- figure out the column names we must support for horizontal cross
    if (p_columnfield is not null) then
    tmp:='SELECT DISTINCT ' || p_columnfield || ' FROM (' || p_query || ') ORDER BY ' || p_columnfield;
    -- dbms_output.put_line('columns cursor:'||tmp);
    OPEN l_cursor for tmp;
    LOOP
    l_columnnames.EXTEND;
    FETCH l_cursor into l_columnnames(l_columnnames.COUNT);
    --dbms_output.put_line('l_columnnames:'||l_columnnames(l_columnnames.COUNT));
    EXIT WHEN l_cursor%NOTFOUND;
    END LOOP;
    CLOSE l_cursor;
    -- execute immediate 'SELECT DISTINCT ' || p_columnfield || ' FROM (' || p_query || ')' bulk collect into l_columnnames ;
    else
    raise_application_error (-20001, 'Cannot figure out max cols');
    end if;
    -- Now, construct the query that can answer the question for us...
    l_query := 'SELECT ' || p_rowfields ;
    l_begcol:=l_cols_per_page*(p_page-1)+1;
    l_endcol:=l_cols_per_page*p_page;
    if l_begcol>l_columnnames.count-1 then
    l_begcol := l_columnnames.count-1;
    end if;
    if l_endcol>l_columnnames.count-1 then
    l_endcol := l_columnnames.count-1;
    end if;
    --for i in  1 .. l_columnnames.count-1 loop
    for i in l_begcol..l_endcol loop
    FormatParam(l_columnnames(i),l_columnfieldtype, o_decode, o_col);--format params
    l_query := l_query || ',' || p_function || '(DECODE(' || p_columnfield || ',' || o_decode || ','|| p_functionfield ||',null)) as "'|| o_col ||'" ' ; --" для строк с пробелами
    end loop;
    l_query := l_query || ' FROM (' || p_query || ')';
    l_query := l_query || ' GROUP BY ' || p_rowfields || ' ORDER BY ' || p_rowfields;
    /* close cursor */
    dbms_sql.close_cursor(l_theCursor);
    return l_query;
    EXCEPTION
    WHEN OTHERS THEN
    /* close cursor */
    dbms_sql.close_cursor(l_theCursor);
    raise_application_error (-20001,'Error in PivotSQL:' || SQLERRM);
    end;
    --=========================
    Procedure FormatParam (var_data in varchar2, var_type in number, out_decode in out varchar2, out_col in out varchar2)
    --format parameter based on its type - for PivotSQL
    --get parameter and its type
    -- return strings for decode function and column name
    /* dbms_sql.describe_columns types:
    DATE Type:12
    Varchar2 Type:1
    Number Type:2
    IS
    BEGIN
    IF var_data is null THEN
    out_decode:='NULL';
    out_col:='==NULL==';
    ELSIF var_type = 1 THEN -- Varchar2
    out_decode:=''''||var_data||'''';--add quotes
    out_col:=substr(var_data,1,30);
    ELSIF var_type = 2 THEN --Number
    out_decode:=var_data;--do nothing
    out_col:=substr(var_data,1,30);
    ELSIF var_type = 12 THEN --DATE
    out_decode:='to_date('''||var_data||''')';--format as internal date
    out_col:=to_char(to_date(var_data),'YYYY-MM-DD');
    ELSE
    out_decode:='== UNDEFINED TYPE:'||var_type;
    out_col:='== UNDEFINED TYPE';
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    raise_application_error (-20001,'Error in FormatParam:' || SQLERRM);
    END;
    end;

    Hi,
    Thank you for providing such an excellent piece of code. I have used it and it works like a charm. However I faced a problem today and needed your help.
    I am executing this code using the following code :
    SELECT PK_PIVOT.PivotSQL('SELECT sfid.bill_date ,cust.customer_name FROM split_file_detail sfd,customer cust,split_file_invoice_details sfid where sfd.CUSTOMER_SYS_ID=cust.CUSTOMER_SYS_ID and sfid.SPLIT_FILE_DETAIL_SYS_ID = sfd.SPLIT_FILE_DETAIL_SYS_ID'
    ,'cust.customer_name','bill_date','count','cust.customer_name') FROM SYS.DUAL
    Now when I do so I get the following error :
    ORA -20001 : Error in PivotSQL: ORA-06502 and ORA-06512.
    Now I guess the error maybe because:
    1. The p_query parameter is huge and the tmp long type is not able to hold the value.
    2. bill_date holds 200+ values and the ref_cursor is not able to handle it.
    I have tried breaking p_query down to some more bits but I face the problem when I concatenate them back together.
    Can you help me please?

  • Pivot not working; Analytics question

    I got a lot done this past weekend on tough query for me but now have more questions. You must run the top query to understand the understand the second.
    Background:
    This is a period to date report which includes amounts from beginning of the year as well as last year.
    My example Report is for Period 9 which begins on Aug 24, 2009
    Period has 5 weeks (Most periods have 4) ;
    Also if period is requested in Week 3 then only weeks 1 and 2 will be reflected on report
    The report looks like this: (Data provided should produce these numbers except for maybe the YTD column.
                 WEEK1       WEEK2           WEEK3         WEEK4             WEEK5       Period-to-date          Year-to-date
    Net - Landau     11,485.79   11,416.60      11,609.01     11,049.76      12,867.10      58,428.00             454,231.37      
    Net - AW     0.00               0.00          0.00        0.00                   0.00          0.00              0.00
    Net - LJS     0.00                   0.00           0.00         0.00           0.00          0.00            0.00
    Net - TB     7,118.17     7,228.13    7,657.94      7,699.53           7,958.53      37,662.00            306,115.59      
    Total Net     18,603.96    18,644.73      19,266.95     18,749.29         20,825.63      96,091.00            760,346.96      
    Last Year Sales     23,515.95    24,244.37       23,962.74    23,134.79      24,440.87      119,299.00           856,363.36      
    Increase     (4,911.99)  (5,599.64)      (4,695.79)  (4,385.50)           (3,615.24)     (23,208.00)           (96,016.40)     
    Last year
      Next Week     24,244.37    23,962.74       23,134.79    24,440.87      23,055.87      118,839.00           879,419.23      --===== Current Year Dates
    Beginning of period: (BOP) Mon Aug 24
    Week 1: Mon Aug 24 - Aug 30
    Week 2: Mon Aug 11 - Sept 6
    Week 3: Mon Sep 7 - Sept 13
    Week 4: Mon Sept 14 - Sept 20
    Week 5: Mon Sept 21 - Sept 27
    Beginning of fiscal year( BOY) = '28-Dec-08'
    --===== Last Year Dates
    Beginning of period: (BOP_LY) Mon Aug 25
    Week 1: Mon Aug 25 - Aug 31
    Week 2: Mon Aug 1 - Sept 7
    Week 3: Mon Sep 8 - Sept 14
    Week 4: Mon Sept 15 - Sept 21
    Week 5: Mon Sept 22 - Sept 28
    Beginning of fiscal year( BOY) = '31-Dec-07'
    My challenge over weekend was to get entire year of data vs. just the period data.
    There are 7 columns on this report. 5 weeks of period, PeriodToDate (total of the weeks) and YearToDate (PeriodToDate + Sum of all data from beginning of year to the end of the previous period.
    I'm not really concerned with the PTD, the program can handle that. I got the BOY date with the following code:
    All data is summed for the week and grouped by storeid and TRUNC(date, 'IW') which is the Monday of each week.
    of each week. (The resultset contains data for 2 stores instead of 1. This is there only to make sure my query was filtering correctly)
    drop table my_csh_main;
    CREATE TABLE MY_CSH_MAIN
       (     "FK_STR_MAIN_ID" NUMBER,
         "BUSI_DATE" DATE,
         "CONF_NUMB2" NUMBER,
         "CONF_NUMB49" NUMBER,
         "CONF_NUMB44" NUMBER,
         "CONF_NUMB3" NUMBER,
         "CONF_NUMB4" NUMBER,
         "CONF_NUMB38" NUMBER,
         "CONF_NUMB56" NUMBER
    REM INSERTING into MY_CSH_MAIN
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('28-AUG-08','DD-MON-RR'),22103.69,0,0,119,0,4605.21,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('27-AUG-09','DD-MON-RR'),18081.37,0,0,0,0,3533.45,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('17-SEP-09','DD-MON-RR'),18211.29,0,0,0,0,3806.32,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('04-SEP-08','DD-MON-RR'),24244.37,0,0,284.94,0,0,9395.63);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('03-SEP-09','DD-MON-RR'),18644.73,0,0,85.48,0,0,7228.13);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('24-SEP-09','DD-MON-RR'),16809.21,0,0,64.99,0,3014.61,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('25-SEP-08','DD-MON-RR'),24440.87,0,0,0,0,0,9469.64);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('28-AUG-08','DD-MON-RR'),23515.95,0,0,0,80.38,0,9379.9);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('24-SEP-09','DD-MON-RR'),20825.63,0,0,73.97,0,0,7958.53);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('17-SEP-09','DD-MON-RR'),18749.29,0,0,0,0,0,7699.53);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('11-SEP-08','DD-MON-RR'),22839.3,0,0,206.39,116.74,4493.28,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('04-SEP-08','DD-MON-RR'),22627.74,0,0,279.98,0,4423.83,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('27-AUG-09','DD-MON-RR'),18603.96,0,0,81.25,0,0,7118.17);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('11-SEP-08','DD-MON-RR'),23962.74,0,0,153.1,0,0,9335.35);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('18-SEP-08','DD-MON-RR'),23134.79,0,0,44.12,0,0,8978.87);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('25-SEP-08','DD-MON-RR'),24950.45,0,0,129.98,0,5330.22,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('10-SEP-09','DD-MON-RR'),19266.95,0,0,0,0,0,7657.94);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('03-SEP-09','DD-MON-RR'),17183.25,0,0,0,0,3487.12,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('18-SEP-08','DD-MON-RR'),21372.82,0,0,0,0,4546.15,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('10-SEP-09','DD-MON-RR'),17688.41,0,0,113.12,0,3424.17,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('31-DEC-08','DD-MON-RR'),611016.24,0,0,1276.62,724.96,122236.02,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('31-DEC-08','DD-MON-RR'),667612.63,0,0,1018.81,0,0,269777.87);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('02-JAN-08','DD-MON-RR'),1676737.13,0,0,5652.47,3850.68,345971.1,500.5);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('02-JAN-08','DD-MON-RR'),1786451.11,0,0,3167.61,175.38,0,788438.73);
      CREATE TABLE  LANDAU_REPORT_STORES
       (     "COMPANYNAME" CHAR(40 BYTE),
         "DISTRICTNAME" VARCHAR2(50 BYTE),
         "STOREID" NUMBER(4,0) NOT NULL ENABLE,
         "STORENAME" VARCHAR2(70 BYTE),
         "STORENBR" CHAR(4 BYTE) NOT NULL ENABLE
    REM INSERTING into LANDAU_REPORT_STORES
    Insert into LANDAU_REPORT_STORES (COMPANYNAME,DISTRICTNAME,STOREID,STORENAME,STORENBR) values ('Landau                                  ','DIST 10',64,'N_Main','0004');
    Insert into LANDAU_REPORT_STORES(COMPANYNAME,DISTRICTNAME,STOREID,STORENAME,STORENBR) values ('Landau                                  ','DIST 10',65,'Belvidere','0005');
    Insert into LANDAU_REPORT_STORES(COMPANYNAME,DISTRICTNAME,STOREID,STORENAME,STORENBR) values ('Landau                                  ','DIST 10',104,'Mulford','0032');
    Insert into LANDAU_REPORT_STORES(COMPANYNAME,DISTRICTNAME,STOREID,STORENAME,STORENBR) values ('Landau                                  ','DIST 50',141,'Charleston','0043');
    Insert into LANDAU_REPORT_STORES(COMPANYNAME,DISTRICTNAME,STOREID,STORENAME,STORENBR) values ('Landau                                  ','DIST 10',61,'Kilburn','0002');
    Insert into LANDAU_REPORT_STORES(COMPANYNAME,DISTRICTNAME,STOREID,STORENAME,STORENBR) values ('Landau                                  ','DIST 10',62,'11th_St','0003');
       with WeeklyTotals as
       ( select                           StoreId
                                         , week_date
                                         , net_sales
                                         , ljs_food_sales
                                         , total_drink_sales
                                         , net_food
                                         , CASE
                                              WHEN net_food is null  then 0
                                              WHEN net_food  = 0  then 0
                                              ELSE Ljs_food_sales / net_food
                                           END as LJS_Percent
                                         , CASE
                                              WHEN net_food is null  then 0
                                              WHEN net_food = 0  then 0
                                              else total_drink_sales * (ljs_food_sales / net_food)
                                           END as LJS_Drinks
                                         , aw_sales
                                         , tb_sales
              FROM                            (Select fk_str_main_id as StoreId,
                                                                               trunc(csh.busi_date, 'IW') as week_date,
                                                                         sum(csh.conf_numb2) As net_sales,
                                                                         sum(conf_numb49) as ljs_food_sales,
                                                                         sum(conf_numb44)  As total_drink_sales,
                                                                         sum(csh.conf_numb2) - sum(CONF_NUMB44) - sum(conf_numb3) - sum(conf_numb4) AS net_food,
                                                                         sum(conf_numb38) As aw_sales,
                                                                         sum(conf_numb56)  as tb_sales
                                                     from my_csh_main csh
                                                     WHERE BUSI_DATE BETWEEN  TO_DATE( '28-Dec-08' ,'DD-MON-YY') AND  TO_DATE( '27-SEP-09' ,'DD-MON-YY')
                                                    and fk_str_main_id in (141, 221)
                                                    GROUP BY CSH.FK_STR_MAIN_ID,    trunc(csh.busi_date, 'IW')
       ,  WeeklyFoodSalesLY as
        SELECT    fk_str_main_id AS storeid
               ,  TRUNC(busi_date, 'iw') week_date
               ,  SUM(csh.conf_numb2) AS net_sales
        FROM   my_csh_main csh
        WHERE busi_date BETWEEN   to_date('31-DEc-07', 'dd-Mon-yy')  and  to_date('28-Sep-08', 'dd-Mon-yy')
        GROUP BY fk_str_main_id, TRUNC(busi_date, 'iw')
      , StoreDetails  AS
             select * from LANDAU_REPORT_STORES where STORENAME NOT like  '%CLOSED%'  order by DistrictNAme, StoreNbr
       Select 
                 foods.storeid
              ,   CASE
                   WHEN   to_date(Foods.week_date, 'dd-Mon-yy')  =  to_date('24-AUG-09', 'dd-Mon-yy')  then 1
                   WHEN   to_date(Foods.week_date, 'dd-Mon-yy')  =  to_date('24-AUG-09', 'dd-Mon-yy') + 7 then 2
                   WHEN   to_date(Foods.week_date, 'dd-Mon-yy')  =  to_date('24-AUG-09', 'dd-Mon-yy') + 14 then 3
                   WHEN   to_date(Foods.week_date, 'dd-Mon-yy')  =  to_date('24-AUG-09','dd-Mon-yy') + 21 then 4
                   WHEN   to_date(Foods.week_date, 'dd-Mon-yy')  =  to_date('24-AUG-09', 'dd-Mon-yy') + 28 then 5
                   ELSE  0
             end as WeekNBr
        ,   foods.week_date  as CurrWeekDate
        ,   foodsLY.week_date as LastYearWEekDate   
        ,   ROUND(NVL(foods.net_sales - (aw_sales + tb_sales + ljs_drinks + ljs_food_sales ), 0), 2) as Landau_Net_Sales
        ,   ROUND(NVL(aw_sales, 0), 2) as aw_sales
        ,   ROUND(NVL(tb_sales, 0), 2) as tb_sales
        ,   ROUND(NVL(ljs_drinks + ljs_food_sales, 0),2)    as ljs_net_sales
        ,   ROUND(NVL(foods.Net_Sales, 0), 2) as net_sales
        --==
        -- Last Year Sales and Last Year Next Year Sales
       --==
    ,    ROUND(NVL(foodsLY.Net_Sales, 0),2)    as    WTDLYNetSales
    ,    ROUND(NVL(Foods.Net_Sales -  FoodsLY.Net_Sales, 0),2)  as    WTDSalesIncrease
    -- ,    ROUND(NVL(FoodsLY_NextWeek.Net_Sales, 0), 2)          as    WTDFoodsSalesLY 
    ,   stores.*
    from WEeklyTotals Foods 
    LEFT OUTER JOIN Weeklyfoodsalesly foodsly ON foodsly.storeid = foods.storeid
                                              AND foodsly.week_date = DECODE(foods.week_date,
                                                                             to_date('24-AUG-09', 'dd-Mon-yy') ,       to_date('25-AUG-08', 'dd-Mon-yy') ,
                                                                             to_date('24-AUG-09', 'dd-Mon-yy')  + 7,   to_date('25-AUG-08', 'dd-Mon-yy') + 7,
                                                                             to_date('24-AUG-09', 'dd-Mon-yy')  + 14,  to_date('25-AUG-08', 'dd-Mon-yy') + 14,
                                                                             to_date('24-AUG-09', 'dd-Mon-yy')  + 21,  to_date('25-AUG-08', 'dd-Mon-yy') + 21,
                                                                             to_date('24-AUG-09', 'dd-Mon-yy')  + 28,  to_date('25-AUG-08', 'dd-Mon-yy') + 28)
    LEFT OUTER  JOIN  StoreDetails             stores  ON     stores.storeid   = Foods.storeid;one exception. In a With statement, I get a recordset containing all of last years data. I could not figure out the Pivot
    to get the Last Year Next Week . That means next week, one year ago. I pulled out a snippet to work with but couldn't get it
    to work:
    The problem came when I tried to pivot the Last year sales. I pulled this snippet out to test with but couldn't make it work.
    with   WeeklyFoodSalesLY  as
    (         SELECT  fk_str_main_id AS storeid
                 ,   TRUNC(busi_date, 'iw') week_date
                 ,   sum(conf_numb2)   conf_numb2
               FROM  my_csh_main csh    
               WHERE busi_date BETWEEN   to_date('31-dec-07', 'dd-Mon-yy')  and  to_date('28-Sep-08', 'dd-Mon-yy') + 7
               and fk_str_main_id = 141  
               GROUP BY  fk_str_main_id , TRUNC(busi_date, 'iw')      
    ,  sales_ly as
    (    SELECT      storeid
                    , week_date
                    , sum(conf_numb2) as net_sales
          from WeeklyFoodSalesLY
          WHERE week_date BETWEEN   to_date('25-Aug-08', 'dd-Mon-yy')  and  to_date('28-Sep-08', 'dd-Mon-yy') 
          GROUP BY  storeid , week_date    
          UNION ALL
          SELECT      storeid
                    , week_date
                    , sum(conf_numb2) as net_sales
          from WeeklyFoodSalesLY
          WHERE week_date BETWEEN   to_date('25-Aug-08', 'dd-Mon-yy') + 7   and  to_date('28-Sep-08', 'dd-Mon-yy') + 7
          GROUP BY  storeid , week_date
          UNION ALL
          SELECT      storeid
                    , week_date
                    , sum(conf_numb2) as net_sales
          from WeeklyFoodSalesLY
          WHERE week_date < to_date('25-Aug-08', 'dd-Mon-yy') 
          GROUP BY  storeid , week_date
    ,  pivoted_sales_ly as
    (    SELECT          storeid
                         week_date
                    ,    MAX(DECODE(week_date, to_date('25-Aug-08', 'dd-Mon-yy'),          net_sales))        as lastyear
                    ,    MAX(DECODE(week_date, to_date('25-Aug-08', 'dd-Mon-yy') + 7,      net_sales))        as lastyearnextweek
                    ,    MAX(DECODE(week_date, to_date('31-dec-07', 'dd-Mon-yy'),          net_sales))        as lastyeartotal
          from sales_ly
          GROUP BY  storeid, week_date
    Select *
    from pivoted_sales_ly;  What am i dont wrong here? Once I get this I can work back into the original query.
    Analytics:
    Boneist gave me some code to try last week:
    Combining refCursors  and Summing
    that created the PTD column.
    I could never get it to work because I was tweaking so much with the Query but is there a way to get the PTD without
    having to add an extra PTD column for each week.
    One other thing:
    I would like to know how to use analytics to roll up report by division into a different cursor.
    Edited by: TheHTMLDJ on Oct 26, 2009 4:50 AM
    Edited by: TheHTMLDJ on Oct 26, 2009 4:59 AM

    TheHTMLDJ wrote:
    The report looks like this: (Data provided should produce these numbers except for maybe the YTD column.With the data you provided, I managed to produce the expected output for storeid 221, barring the YTD column, which had the wrong values. I had to make up the "next week" row for the previous year for storeid 221, btw:
    WITH weekly_values AS (SELECT fk_str_main_id as storeid,
                                  TRUNC(csh.busi_date, 'IW') AS week_date,
                                  NVL(SUM(csh.conf_numb2), 0) AS net_sales,
                                  NVL(SUM(conf_numb49), 0) AS ljs_food_sales,
                                  NVL(SUM(conf_numb44), 0) AS total_drink_sales,
                                  NVL(SUM(csh.conf_numb2) - SUM(conf_numb44)
                                                          - SUM(conf_numb3)
                                                          - SUM(conf_numb4), 0) AS net_food,
                                  NVL(SUM(conf_numb38), 0) AS aw_sales,
                                  NVL(SUM(conf_numb56), 0) AS tb_sales
                           FROM   my_csh_main csh
                           WHERE  (busi_date BETWEEN TRUNC(:v_bop, 'iy') AND TRUNC(:v_bop, 'iw') + 7*(:v_num_weeks - 1) + 6
                                   OR
                                   busi_date BETWEEN TRUNC(:v_bop_ly, 'iy') AND TRUNC(:v_bop_ly, 'iw') + 7*:v_num_weeks  + 6)
                           AND    fk_str_main_id IN (141, 221)
                           GROUP BY csh.fk_str_main_id,
                                    TRUNC(csh.busi_date, 'IW')),
         weekly_totals AS (SELECT storeid,
                                  week_date,
                                  net_sales,
                                  ljs_food_sales,
                                  total_drink_sales,
                                  net_food,
                                  CASE WHEN nvl(net_food, 0) = 0 then 0
                                       ELSE ljs_food_sales / net_food
                                  END AS ljs_percent,
                                  CASE WHEN nvl(net_food, 0) = 0 then 0
                                       ELSE total_drink_sales * (ljs_food_sales / net_food)
                                  END AS ljs_drinks,
                                  aw_sales,
                                  tb_sales,
                                  net_sales - aw_sales
                                            - tb_sales
                                            - ljs_food_sales
                                            - CASE WHEN nvl(net_food, 0) = 0 then 0
                                                   ELSE total_drink_sales * (ljs_food_sales / net_food)
                                              END AS landau_net_sales
                           FROM   weekly_values),
         week_tots_ytd AS (SELECT storeid,
                                  week_date,
                                  net_sales,
                                  ljs_food_sales,
                                  total_drink_sales,
                                  net_food,
                                  ljs_drinks,
                                  aw_sales,
                                  tb_sales,
                                  landau_net_sales,
                                  SUM(decode(week_date, TRUNC(:v_bop_ly, 'iw') + 7*:v_num_weeks, NULL, landau_net_sales)) OVER (PARTITION BY storeid,
                                                                                                                                             trunc(week_date, 'iy')) lns_ytd,
                                  SUM(decode(week_date, TRUNC(:v_bop_ly, 'iw') + 7*:v_num_weeks, NULL, aw_sales)) OVER (PARTITION BY storeid,
                                                                                                                                     trunc(week_date, 'iy')) aws_ytd,
                                  SUM(decode(week_date, TRUNC(:v_bop_ly, 'iw') + 7*:v_num_weeks, NULL, ljs_food_sales)) OVER (PARTITION BY storeid,
                                                                                                                                           trunc(week_date, 'iy')) ljsf_ytd,
                                  SUM(decode(week_date, TRUNC(:v_bop_ly, 'iw') + 7*:v_num_weeks, NULL, tb_sales)) OVER (PARTITION BY storeid,
                                                                                                                                     trunc(week_date, 'iy')) tbs_ytd,
                                  SUM(decode(week_date, TRUNC(:v_bop_ly, 'iw') + 7*:v_num_weeks, NULL, net_sales)) OVER (PARTITION BY storeid,
                                                                                                                                      trunc(week_date, 'iy')) net_ytd,
                                  SUM(net_sales) OVER (PARTITION BY storeid,
                                                                    trunc(week_date, 'iy')) full_net_ytd,
                                  SUM(landau_net_sales) OVER (PARTITION BY storeid,
                                                                           CASE WHEN week_date between TRUNC(:v_bop, 'iw') and TRUNC(:v_bop, 'iw') + 7*(:v_num_weeks -1) THEN 1
                                                                                WHEN week_date between TRUNC(:v_bop_ly, 'iw') and TRUNC(:v_bop_ly, 'iw') + 7*(:v_num_weeks -1) THEN 2
                                                                           END) lns_ptd,
                                  SUM(aw_sales) OVER (PARTITION BY storeid,
                                                                   CASE WHEN week_date between TRUNC(:v_bop, 'iw') and TRUNC(:v_bop, 'iw') + 7*(:v_num_weeks -1) THEN 1
                                                                        WHEN week_date between TRUNC(:v_bop_ly, 'iw') and TRUNC(:v_bop_ly, 'iw') + 7*(:v_num_weeks -1) THEN 2
                                                                   END) aws_ptd,
                                  SUM(ljs_food_sales) OVER (PARTITION BY storeid,
                                                                         CASE WHEN week_date between TRUNC(:v_bop, 'iw') and TRUNC(:v_bop, 'iw') + 7*(:v_num_weeks -1) THEN 1
                                                                              WHEN week_date between TRUNC(:v_bop_ly, 'iw') and TRUNC(:v_bop_ly, 'iw') + 7*(:v_num_weeks -1) THEN 2
                                                                         END) ljsf_ptd,
                                  SUM(tb_sales) OVER (PARTITION BY storeid,
                                                                   CASE WHEN week_date between TRUNC(:v_bop, 'iw') and TRUNC(:v_bop, 'iw') + 7*(:v_num_weeks -1) THEN 1
                                                                        WHEN week_date between TRUNC(:v_bop_ly, 'iw') and TRUNC(:v_bop_ly, 'iw') + 7*(:v_num_weeks -1) THEN 2
                                                                   END) tbs_ptd,
                                  SUM(net_sales) OVER (PARTITION BY storeid,
                                                                    CASE WHEN week_date between TRUNC(:v_bop, 'iw') and TRUNC(:v_bop, 'iw') + 7*(:v_num_weeks -1) THEN 1
                                                                         WHEN week_date between TRUNC(:v_bop_ly, 'iw') and TRUNC(:v_bop_ly, 'iw') + 7*(:v_num_weeks-1) THEN 2
                                                                    END) net_ptd,
                                  LEAD(net_sales) OVER (PARTITION BY storeid,
                                                                     trunc(week_date, 'iy')
                                                        ORDER BY week_date) next_week_net_sales
                           FROM   weekly_totals),
                 foods AS (Select storeid,
                                  CASE WHEN week_date in (:v_bop, :v_bop_ly) then 1
                                       WHEN week_date in (:v_bop + 7, :v_bop_ly + 7) then 2
                                       WHEN week_date in (:v_bop + 14, :v_bop_ly + 14) then 3
                                       WHEN week_date in (:v_bop + 21, :v_bop_ly + 21) then 4
                                       WHEN week_date in (:v_bop + 28, :v_bop_ly + 28) then 5
                                  END AS week_number,
                                  week_date,
                                  ROUND(net_sales - (aw_sales + tb_sales + ljs_drinks + ljs_food_sales), 2) AS landau_net_sales,
                                  ROUND(aw_sales, 2) AS aw_sales,
                                  ROUND(tb_sales, 2) AS tb_sales,
                                  ROUND(ljs_drinks + ljs_food_sales, 2) AS ljs_net_sales,
                                  ROUND(net_sales, 2) AS net_sales,
                                  ROUND(lns_ytd, 2) AS lns_ytd,
                                  ROUND(aws_ytd, 2) AS aws_ytd,
                                  ROUND(ljsf_ytd, 2) AS ljsf_ytd,
                                  ROUND(tbs_ytd, 2) AS tbs_ytd,
                                  ROUND(net_ytd, 2) AS net_ytd,
                                  ROUND(full_net_ytd, 2) AS full_net_ytd,
                                  ROUND(lns_ptd, 2) AS lns_ptd,
                                  ROUND(aws_ptd, 2) AS aws_ptd,
                                  ROUND(ljsf_ptd, 2) AS ljsf_ptd,
                                  ROUND(tbs_ptd, 2) AS tbs_ptd,
                                  ROUND(net_ptd, 2) AS net_ptd,
                                  ROUND(next_week_net_sales, 2) AS next_week_net_sales,
                                  SUM(ROUND(next_week_net_sales, 2)) OVER (PARTITION BY storeid,
                                                                                       TRUNC(week_date, 'iy')) nwns_ptd
                           FROM   week_tots_ytd
                           WHERE  (week_date BETWEEN TRUNC(:v_bop, 'iw') AND TRUNC(:v_bop, 'iw') + 7*(:v_num_weeks - 1)
                                   OR
                                   week_date BETWEEN TRUNC(:v_bop_ly, 'iw') AND TRUNC(:v_bop_ly, 'iw') + 7*(:v_num_weeks - 1))),
         pivoted_foods AS (SELECT storeid,
                                  week_number,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), landau_net_sales)) landau_net_sales,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), aw_sales)) aw_sales,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), tb_sales)) tb_sales,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), ljs_net_sales)) ljs_net_sales,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), net_sales)) net_sales,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), lns_ytd)) lns_ytd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), aws_ytd)) aws_ytd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), ljsf_ytd)) ljsf_ytd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), tbs_ytd)) tbs_ytd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), net_ytd)) net_ytd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), full_net_ytd)) full_net_ytd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), lns_ptd)) lns_ptd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), aws_ptd)) aws_ptd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), ljsf_ptd)) ljsf_ptd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), tbs_ptd)) tbs_ptd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), net_ptd)) net_ptd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop_ly, 'iy'), net_sales)) ly_net_sales,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop_ly, 'iy'), net_ytd)) ly_net_ytd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop_ly, 'iy'), net_ptd)) ly_net_ptd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop_ly, 'iy'), next_week_net_sales)) ly_next_week_net_sales,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop_ly, 'iy'), nwns_ptd)) ly_nwns_ptd
                           FROM   foods
                           GROUP BY storeid,
                                    week_number),
          storedetails AS (SELECT companyname,
                                  districtname,
                                  storeid,
                                  storename,
                                  storenbr
                           FROM   landau_report_stores
                           WHERE  UPPER(storename) NOT LIKE  '%CLOSED%' 
                           ORDER BY districtname, storenbr),
                 dummy AS (SELECT level col1
                           FROM   dual
                           CONNECT BY level <= 8)
    SELECT pf.storeid,
           DECODE(dummy.col1, 1, 'Net - Landau',
                              2, 'Net - AW',
                              3, 'Net - LJS',
                              4, 'Net - TB',
                              5, 'Total Net',
                              6, 'Last Year Sales',
                              7, 'Increase',
                              8, 'Last Year Next Week') category,
           SUM(CASE WHEN pf.week_number = 1 AND dummy.col1 = 1 THEN pf.landau_net_sales
                    WHEN pf.week_number = 1 AND dummy.col1 = 2 THEN pf.aw_sales
                    WHEN pf.week_number = 1 AND dummy.col1 = 3 THEN pf.ljs_net_sales
                    WHEN pf.week_number = 1 AND dummy.col1 = 4 THEN pf.tb_sales
                    WHEN pf.week_number = 1 AND dummy.col1 = 5 THEN pf.net_sales
                    WHEN pf.week_number = 1 AND dummy.col1 = 6 THEN pf.ly_net_sales
                    WHEN pf.week_number = 1 AND dummy.col1 = 7 THEN pf.net_sales - pf.ly_net_sales
                    WHEN pf.week_number = 1 AND dummy.col1 = 8 THEN pf.ly_next_week_net_sales
           END) week1,
           SUM(CASE WHEN pf.week_number = 2 AND dummy.col1 = 1 THEN pf.landau_net_sales
                    WHEN pf.week_number = 2 AND dummy.col1 = 2 THEN pf.aw_sales
                    WHEN pf.week_number = 2 AND dummy.col1 = 3 THEN pf.ljs_net_sales
                    WHEN pf.week_number = 2 AND dummy.col1 = 4 THEN pf.tb_sales
                    WHEN pf.week_number = 2 AND dummy.col1 = 5 THEN pf.net_sales
                    WHEN pf.week_number = 2 AND dummy.col1 = 6 THEN pf.ly_net_sales
                    WHEN pf.week_number = 2 AND dummy.col1 = 7 THEN pf.net_sales - pf.ly_net_sales
                    WHEN pf.week_number = 2 AND dummy.col1 = 8 THEN pf.ly_next_week_net_sales
           END) week2,
           SUM(CASE WHEN pf.week_number = 3 AND dummy.col1 = 1 THEN pf.landau_net_sales
                    WHEN pf.week_number = 3 AND dummy.col1 = 2 THEN pf.aw_sales
                    WHEN pf.week_number = 3 AND dummy.col1 = 3 THEN pf.ljs_net_sales
                    WHEN pf.week_number = 3 AND dummy.col1 = 4 THEN pf.tb_sales
                    WHEN pf.week_number = 3 AND dummy.col1 = 5 THEN pf.net_sales
                    WHEN pf.week_number = 3 AND dummy.col1 = 6 THEN pf.ly_net_sales
                    WHEN pf.week_number = 3 AND dummy.col1 = 7 THEN pf.net_sales - pf.ly_net_sales
                    WHEN pf.week_number = 3 AND dummy.col1 = 8 THEN pf.ly_next_week_net_sales
           END) week3,
           SUM(CASE WHEN pf.week_number = 4 AND dummy.col1 = 1 THEN pf.landau_net_sales
                    WHEN pf.week_number = 4 AND dummy.col1 = 2 THEN pf.aw_sales
                    WHEN pf.week_number = 4 AND dummy.col1 = 3 THEN pf.ljs_net_sales
                    WHEN pf.week_number = 4 AND dummy.col1 = 4 THEN pf.tb_sales
                    WHEN pf.week_number = 4 AND dummy.col1 = 5 THEN pf.net_sales
                    WHEN pf.week_number = 4 AND dummy.col1 = 6 THEN pf.ly_net_sales
                    WHEN pf.week_number = 4 AND dummy.col1 = 7 THEN pf.net_sales - pf.ly_net_sales
                    WHEN pf.week_number = 4 AND dummy.col1 = 8 THEN pf.ly_next_week_net_sales
           END) week4,
           SUM(CASE WHEN pf.week_number = 5 AND dummy.col1 = 1 THEN pf.landau_net_sales
                    WHEN pf.week_number = 5 AND dummy.col1 = 2 THEN pf.aw_sales
                    WHEN pf.week_number = 5 AND dummy.col1 = 3 THEN pf.ljs_net_sales
                    WHEN pf.week_number = 5 AND dummy.col1 = 4 THEN pf.tb_sales
                    WHEN pf.week_number = 5 AND dummy.col1 = 5 THEN pf.net_sales
                    WHEN pf.week_number = 5 AND dummy.col1 = 6 THEN pf.ly_net_sales
                    WHEN pf.week_number = 5 AND dummy.col1 = 7 THEN pf.net_sales - pf.ly_net_sales
                    WHEN pf.week_number = 5 AND dummy.col1 = 8 THEN pf.ly_next_week_net_sales
           END) week5,
           SUM(CASE WHEN pf.week_number = 5 AND dummy.col1 = 1 THEN pf.lns_ptd
                    WHEN pf.week_number = 5 AND dummy.col1 = 2 THEN pf.aws_ptd
                    WHEN pf.week_number = 5 AND dummy.col1 = 3 THEN pf.ljsf_ptd
                    WHEN pf.week_number = 5 AND dummy.col1 = 4 THEN pf.tbs_ptd
                    WHEN pf.week_number = 5 AND dummy.col1 = 5 THEN pf.net_ptd
                    WHEN pf.week_number = 5 AND dummy.col1 = 6 THEN pf.ly_net_ptd
                    WHEN pf.week_number = 5 AND dummy.col1 = 7 THEN pf.net_ptd - pf.ly_net_ptd
                    WHEN pf.week_number = 5 AND dummy.col1 = 8 THEN pf.ly_nwns_ptd
           END) period_to_date,
           SUM(CASE WHEN pf.week_number = 5 AND dummy.col1 = 1 THEN pf.lns_ytd
                    WHEN pf.week_number = 5 AND dummy.col1 = 2 THEN pf.aws_ytd
                    WHEN pf.week_number = 5 AND dummy.col1 = 3 THEN pf.ljsf_ytd
                    WHEN pf.week_number = 5 AND dummy.col1 = 4 THEN pf.tbs_ytd
                    WHEN pf.week_number = 5 AND dummy.col1 = 5 THEN pf.net_ytd
                    WHEN pf.week_number = 5 AND dummy.col1 = 6 THEN pf.ly_net_ytd
                    WHEN pf.week_number = 5 AND dummy.col1 = 7 THEN pf.net_ytd - pf.ly_net_ytd
                    WHEN pf.week_number = 5 AND dummy.col1 = 8 THEN pf.full_net_ytd
           END) year_to_date,
           stores.companyname,
           stores.districtname,
           stores.storename,
           stores.storenbr 
    FROM   pivoted_foods pf
           LEFT OUTER JOIN storedetails stores ON stores.storeid = pf.storeid,
           dummy
    group by dummy.col1,
             DECODE(dummy.col1, 1, 'Net - Landau',
                              2, 'Net - AW',
                              3, 'Net - LJS',
                              4, 'Net - TB',
                              5, 'Total Net',
                              6, 'Last Year Sales',
                              7, 'Increase',
                              8, 'Last Year Next Week'),
             rollup((pf.storeid,
             stores.companyname,
             stores.districtname,
             stores.storename,
             stores.storenbr))
    order by pf.storeid, dummy.col1;(replace all :v_num_weeks, :v_bop and :v_bop_ly references with your variables)

Maybe you are looking for

  • Hello, I am getting an HP Battery Alert, Do I need to replace?. It says it may need replacement.

    I am wondering if I really do need to change my battery on my HP Pavillion dv7. my Pc is about 2 years old and just got that message when starting my PC.  It says HP Battery Alert The system has detected the storage capacity of the battery stated bel

  • Error 404 missing page with BO EDGE 3.1 SP3 - Tomcat via wdeploy

    Hi, We have a problem with the deployment of the webapps on Tomcat 5.5 (5.5.31) of our BO Edge 3.1 SP3 installation. All seems to be working fine untill we try to open a WebI document or try to create a new document (any).  Whenever we try to perform

  • Php form mailer help

    I have this form that I got to work with my flash file. There is part of the php that should send an acknowledgement email and it seems to be not working. I am wondering if someone could explain what I am missing. I think I have everything working do

  • SetIndeterminate mode in Progress Bar

    hi, want to display a ProgressBar in Indeterminate mode. But how do I set it in Indeterminate mode? progressBar.setIndeterminate doesn'e exist. thanx, oli

  • Multiprocessing Preview issues after October CC update

    After the October CC update to After Effects (12.1.0.168) I am experiencing multiprocessing RAM-preview render issues in compositions regardless of presence of any effects or of the format of the media. This manifests itself as intermittent flashing