Cross tab query dynamically.

Hi,
i want to do crosstab in my query. but the data was not static its dynamic.
CREATE TABLE ABTEST
  SEC_ID      NUMBER,
  MONYEAR     VARCHAR2(10 BYTE),
  NUM         NUMBER
SET DEFINE OFF;
Insert into ABTEST
WHERE
   (SEC_ID, MONYEAR, NUM)
Values
   (91, '200802', 13);
Insert into ABTEST
WHERE
   (SEC_ID, MONYEAR, NUM)
Values
   (91, '200803', 25);
Insert into ABTEST
WHERE
   (SEC_ID, MONYEAR, NUM)
Values
   (91, '200804', 26);
Insert into ABTEST
WHERE
   (SEC_ID, MONYEAR, NUM)
Values
   (91, '200805', 13);
Insert into ABTEST
WHERE
   (SEC_ID, MONYEAR, NUM)
Values
   (91, '200806', 10);
Insert into ABTEST
WHERE
   (SEC_ID, MONYEAR, NUM)
Values
   (91, '200807', 11);
Insert into ABTEST
WHERE
   (SEC_ID, MONYEAR, NUM)
Values
   (91, '200808', 5);
Insert into ABTEST
WHERE
   (SEC_ID, MONYEAR, NUM)
Values
   (91, '200809', 14);
Insert into ABTEST
WHERE
   (SEC_ID, MONYEAR, NUM)
Values
   (91, '200810', 17);
Insert into ABTEST
WHERE
   (SEC_ID, MONYEAR, NUM)
Values
   (91, '200811', 12);
Insert into ABTEST
WHERE
   (SEC_ID, MONYEAR, NUM)
Values
   (91, '200812', 12);
COMMIT;
Currently it looks like below.
SEC_ID     MONYEAR     NUM
91     200802     13
91     200803     25
91     200804     26
91     200805     13
91     200806     10
91     200807     11
91     200808     5
91     200809     14
91     200810     17
91     200811     12
91     200812     12
I want to display the data like below.
sec_id 200802 ........200812
91      13                12is there any can we do that by sql query or procedure. The dates are not limited its dynamic.
Please help meout.
Thanks & Regards,
Venkat.

Hi,
The number of columns has to be hard-coded.
If you don't know the number of columns until run-time, then you have to use dynamic SQL where, at run-time, you figure out how many columns are needed and write that many columns.
See the script below for one way of doing that in SQL*Plus.
How to Pivot a Table with a Dynamic Number of Columns
This works in any version of Oracle
The "SELECT ... PIVOT" feature introduced in Oracle 11
is much better for producing XML output.
Say you want to make a cross-tab output of
the scott.emp table.
Each row will represent a department.
There will be a separate column for each job.
Each cell will contain the number of employees in
     a specific department having a specific job.
The exact same solution must work with any number
of departments and columns.
(Within reason: there's no guarantee this will work if you
want 2000 columns.)
Case 0 "Basic Pivot" shows how you might hard-code three
job types, which is exactly what you DON'T want to do.
Case 1 "Dynamic Pivot" shows how get the right results
dynamically, using SQL*Plus. 
(This can be easily adapted to PL/SQL or other tools.)
PROMPT     ==========  0. Basic Pivot  ==========
SELECT     deptno
,     COUNT (CASE WHEN job = 'ANALYST' THEN 1 END)     AS analyst_cnt
,     COUNT (CASE WHEN job = 'CLERK'   THEN 1 END)     AS clerk_cnt
,     COUNT (CASE WHEN job = 'MANAGER' THEN 1 END)     AS manager_cnt
FROM     scott.emp
WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY     deptno
ORDER BY     deptno
PROMPT     ==========  1. Dynamic Pivot  ==========
--     *****  Start of dynamic_pivot.sql  *****
-- Suppress SQL*Plus features that interfere with raw output
SET     FEEDBACK     OFF
SET     PAGESIZE     0
SPOOL     p:\sql\cookbook\dynamic_pivot_subscript.sql
SELECT     DISTINCT
     ',     COUNT (CASE WHEN job = '''
||     job
||     ''' '     AS txt1
,     'THEN 1 END)     AS '
||     job
||     '_CNT'     AS txt2
FROM     scott.emp
ORDER BY     txt1;
SPOOL     OFF
-- Restore SQL*Plus features suppressed earlier
SET     FEEDBACK     ON
SET     PAGESIZE     50
SPOOL     p:\sql\cookbook\dynamic_pivot.lst
SELECT     deptno
@@dynamic_pivot_subscript
FROM     scott.emp
GROUP BY     deptno
ORDER BY     deptno
SPOOL     OFF
--     *****  End of dynamic_pivot.sql  *****
EXPLANATION:
The basic pivot assumes you know the number of distinct jobs,
and the name of each one.  If you do, then writing a pivot query
is simply a matter of writing the correct number of ", COUNT ... AS ..."\
lines, with the name entered in two places on each one.  That is easily
done by a preliminary query, which uses SPOOL to write a sub-script
(called dynamic_pivot_subscript.sql in this example).
The main script invokes this sub-script at the proper point.
In practice, .SQL scripts usually contain one or more complete
statements, but there's nothing that says they have to.
This one contains just a fragment from the middle of a SELECT statement.
Before creating the sub-script, turn off SQL*Plus features that are
designed to help humans read the output (such as headings and
feedback messages like "7 rows selected.", since we do not want these
to appear in the sub-script.
Turn these features on again before running the main query.
*/

Similar Messages

  • Cross Tab Query - Help

    Dear users,
    I have a query as below:
    select a$acct$company company,
    a$period_name "Period Name",
    a$acct$location location,
    a$acct$prime_sub "Prime Sub",
    sum (balance) balance
    from apps_rpt.us_gl_balances
    where a$acct$prime_sub between '300001' and '313099'
    and a$period_name = 'DEC-01'
    and a$acct$company in ('5110')
    group by a$period_name, a$acct$location, a$acct$company, a$acct$prime_sub
    order by a$acct$prime_sub;
    Sample output of the above query is:
    COMPANY     Period Name LOCATION     Prime Sub     BALANCE
    5110     DEC-01         50008     300001              0.00
    5110     DEC-01         52424     300001              0.00
    5110     DEC-01         52513     300001              0.00
    5110     DEC-01         50008     300008              201315.00
    5110     DEC-01         50095     300008              10403.17
    5110     DEC-01         50107     300008              0.00
    5110     DEC-01         50108     300008              -1099236.04
    5110     DEC-01         50180     300008              0.00
    5110     DEC-01         51628     300008              -6396.02
    5110     DEC-01         51734     300008              -5896.51
    5110     DEC-01         51735     300008              -8525.78
    5110     DEC-01         52423     300008              -7268.64
    5110     DEC-01         52424     300008              -6945.65
    5110     DEC-01         52428     300008              -7845.70
    5110     DEC-01         52513     300008              -11309.44
    5110     DEC-01         52514     300008              -10272.08
    5110     DEC-01         52515     300008              -3861.72
    5110     DEC-01         52516     300008              -6685.85I need to write a cross tab query whose output should be some thing as below:
                         300001          300008
    50008                  0             201315.00
    52424                  0            -6945.65
    52513                  0            -11309.44
    50095                  0            10403.17 
    50107                  0            0
    50108                  0            -1099236.04
    50180                  0            0
    51628                   0           -6396.02
    51734                  0           -5896.51
    51735                  0           -8525.78
    52423                  0           -7268.64
    52428                  0           -7845.70
    52514                  0           -10272.08
    52515                  0           -3861.72
    52516                  0           -6685.85from the above cross tab results 300001 and 300008 are Prime Sub and the amount shown is Balance. The columns to the left side is Location. Company and Period Name remain the same for all the rows.
    It would great if some one can assist me in writing a cross tab query to display results as shown above.
    Thanks
    Sandeep

    Frank,
    Thanks for your reply. I Tried your method of Dynamic Pivot, but its not working.
    My dynamic_pivot_subscript.sql script is :
    SELECT DISTINCT
           ',     MAX(DECODE(PRIME_SUB,'|| PRIME_SUB||','  AS txt1,
           'BALANCE,0))  AS '||prime_sub AS txt2
    FROM
    SELECT  a$acct$location         AS LOCATION
    ,       a$acct$prime_sub        AS PRIME_SUB
    ,       SUM(BALANCE)            AS BALANCE
    FROM    apps_rpt.us_gl_balances
    WHERE   a$acct$prime_sub        BETWEEN '300001' AND '313099'
    AND     a$period_name           = 'DEC-01'
    AND     a$acct$company          IN ('5110')
    GROUP BY a$acct$location,a$acct$prime_sub
    );Sql Plus session is as follows :
    -- Restore SQL*Plus features suppressed earlier
    SET     FEEDBACK     ON
    SET     PAGESIZE     50
    SPOOL     p:\sql\cookbook\dynamic_pivot.lst
    select LOCATION
    @@dynamic_pivot_subscript
    from
            SELECT  a$acct$location         AS LOCATION
            ,       a$acct$prime_sub        AS PRIME_SUB
            ,       SUM(BALANCE)            AS BALANCE
            FROM    apps_rpt.us_gl_balances
            WHERE   a$acct$prime_sub        BETWEEN '300001' AND '313099'
            AND     a$period_name           = 'DEC-01'
            AND     a$acct$company          IN ('5110')
            GROUP BY a$acct$location,a$acct$prime_sub
    GROUP BY LOCATION
    SPOOL     OFFWhen i use sql plus session then its giving me the following error:
    @@dynamic_pivot_subscript
    ERROR at line 2:
    ORA-02019: connection description for remote database not found
    (1) The version of Oracle (and any other relevant software) you're using
    Ans :
    Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
    With the Partitioning option
    JServer Release 8.1.7.4.0 - 64bit Production
    I either use Toad or Sql Navigator

  • How to produce dynamic cross-tab query result on this data ?

    Hi gurus,
    I have sales (simplified) sales data as below :
    create table sales_summ (area_code varchar2(3), sales_amt number, product varchar2(10) ) ;
    insert into sales_summ values ('A01', 100, 'P01');
    insert into sales_summ values ('A02', 200, 'P01');
    insert into sales_summ values ('B01', 300, 'P02');
    insert into sales_summ values ('A01', 400, 'P02');
    insert into sales_summ values ('A02', 500, 'P01');
    insert into sales_summ values ('A03', 600, 'P01');
    insert into sales_summ values ('A01', 700, 'P02');
    insert into sales_summ values ('A02', 800, 'P02');
    insert into sales_summ values ('A03', 900, 'P01');
    And I want to produce a cross-tab sales summary like below :
    Product A01 A02 A03 B01
    P01     100          700     1500          0
    P02     1100          800     0          300
    How is the query ?
    Thank you for your help,
    xtanto

    Search this forum for "pivot". Plenty of examples.
    Regards,
    Rob.

  • Help on cross tab query

    Hi all
    I need an help
    SELECT * FROM TABLE_A
    ID SCHEDULED MARK
    1 01/18/2011 T01
    2 01/18/2011 T02
    3 01/18/2011 T03
    4 01/19/2011 T04
    5 01/20/2011 T05 I want Results like below for folllowing query
    SELECT SCHEDULED,MARK FROM TABLE_A
    WHERE SCHEDULED BETWEEN TO_CHAR(SYSDATE,'MM/DD/YYYY') AND TO_CHAR(SYSDATE +1,'MM/DD/YYYY')
    1/18/2010 1/19/2011
    T01           T04
    T02
    T03
    CREATE TABLE  "TABLE_A"
       (     "ID" NUMBER,
         "SCHEDULED" DATE,
         "MARK" VARCHAR2(50)
    insert into table_a values(1, '01/18/2011', 'T01');
    insert into table_a values( 2, ' 01/18/2011', 'T02');
    insert into table_a values( 3, ' 01/18/2011', 'T03');
    insert into table_a values( 4, ' 01/19/2011', 'T04');
    commit;Thanks for your help

    user1849 wrote:
    Hi all
    I need an help
    SELECT * FROM TABLE_A
    ID SCHEDULED MARK
    1 01/18/2011 T01
    2 01/18/2011 T02
    3 01/18/2011 T03
    4 01/19/2011 T04
    5 01/20/2011 T05 I want Results like below for folllowing query
    SELECT SCHEDULED,MARK FROM TABLE_A
    WHERE SCHEDULED BETWEEN TO_CHAR(SYSDATE,'MM/DD/YYYY') AND TO_CHAR(SYSDATE +1,'MM/DD/YYYY')
    1/18/2010 1/19/2011
    T01           T04
    T02
    T03
    CREATE TABLE  "TABLE_A"
    (     "ID" NUMBER,
         "SCHEDULED" DATE,
         "MARK" VARCHAR2(50)
    insert into table_a values(1, '01/18/2011', 'T01');
    insert into table_a values( 2, ' 01/18/2011', 'T02');
    insert into table_a values( 3, ' 01/18/2011', 'T03');
    insert into table_a values( 4, ' 01/19/2011', 'T04');
    commit;Thanks for your helphttp://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:766825833740

  • Cross tab query

    I have a question about a correlation table and getting the results whether it is there or not. I've done this in SQL Server's product but haven't had success transferring it to ORACLE. Here is the situation:
    I have a table of visitors, a table of visitor attributes and a table correlating the visitor to the attributes. The visitor doesn't need to have all of the attributes. In SQL Server I use a left outer join and join on the visitor attribute value (the correlation table) one time for each attribute in the visitor attribute table. The result should be a query that returns a recordset of all visitors with all attributes as the columns with NULL where there is no attribute value and (obviously) a value where there is one. Any help would be greatly appreciated. (Please CC responses to [email protected]).
    Here is the query that I use in SQL server:
    SELECT
    V.id id,
    V.firstvisit firstvisit,
    V.lastvisit lastvisit,
    V.visitcount visitcount,
    VAV_PHON.ATTRIBUTEVALUE Phone,
    VAV_STAT.ATTRIBUTEVALUE State,
    VAV_CITY.ATTRIBUTEVALUE City,
    VAV_ADDR.ATTRIBUTEVALUE Address,
    VAV_LAST.ATTRIBUTEVALUE Last_Name,
    VAV_FIRS.ATTRIBUTEVALUE First_Name
    FROM WT_TEST3.DBO.TBL_VISITOR V
    LEFT OUTER JOIN WT_TEST3.DBO.TBL_VISITORATRVAL VAV_PHON ON
    (VAV_PHON.VISITOR_ID = V.ID AND VAV_PHON.ATTRIBUTE_ID = 12)
    LEFT OUTER JOIN WT_TEST3.DBO.TBL_VISITORATRVAL VAV_STAT ON
    (VAV_STAT.VISITOR_ID = V.ID AND VAV_STAT.ATTRIBUTE_ID = 11)
    LEFT OUTER JOIN WT_TEST3.DBO.TBL_VISITORATRVAL VAV_CITY ON
    (VAV_CITY.VISITOR_ID = V.ID AND VAV_CITY.ATTRIBUTE_ID = 10)
    LEFT OUTER JOIN WT_TEST3.DBO.TBL_VISITORATRVAL VAV_ADDR ON
    (VAV_ADDR.VISITOR_ID = V.ID AND VAV_ADDR.ATTRIBUTE_ID = 9)
    LEFT OUTER JOIN WT_TEST3.DBO.TBL_VISITORATRVAL VAV_LAST ON
    (VAV_LAST.VISITOR_ID = V.ID AND VAV_LAST.ATTRIBUTE_ID = 8)
    LEFT OUTER JOIN WT_TEST3.DBO.TBL_VISITORATRVAL VAV_FIRS ON
    (VAV_FIRS.VISITOR_ID = V.ID AND VAV_FIRS.ATTRIBUTE_ID = 7)
    null

    Hi David,
    the syntax in Oracle is:
    SELECT
    V.id id,
    V.firstvisit firstvisit,
    V.lastvisit lastvisit,
    V.visitcount visitcount,
    VAV_PHON.ATTRIBUTEVALUE Phone,
    VAV_STAT.ATTRIBUTEVALUE State,
    VAV_CITY.ATTRIBUTEVALUE City,
    VAV_ADDR.ATTRIBUTEVALUE Address,
    VAV_LAST.ATTRIBUTEVALUE Last_Name,
    VAV_FIRS.ATTRIBUTEVALUE First_Name
    FROM dbo.tbl_visitor v ,
    dbo.TBL_VISITORATRVAL VAV_PHON,
    dbo.TBL_VISITORATRVAL VAV_STAT,
    dbo.TBL_VISITORATRVAL VAV_CITY,
    dbo.TBL_VISITORATRVAL VAV_ADDR,
    dbo.TBL_VISITORATRVAL VAV_LAST,
    dbo.TBL_VISITORATRVAL VAV_FIRS
    WHERE vav_phon.visitor_id (+)= v.id
    AND vav_phon.attribute_id (+)= 12
    AND vav_stat.visitor_id (+)= v.id
    AND vav_stat.attribute_id (+)= 11
    AND vav_city.visitor_id (+)= v.id
    AND vav_city.attribute_id (+)= 10
    AND vav_addr.visitor_id (+)= v.id
    AND vav_addr.attribute_id (+)= 9
    AND vav_last.visitor_id (+)= v.id
    AND vav_last.attribute_id (+)= 8
    AND vav_firs.visitor_id (+)= v.id
    AND vav_firs.attribute_id (+)= 11The outer join operator is (+).
    Bye Max
    null

  • SQL cross tab query

    how do you do the equivilent in a webi report?
    I dont think case statements are supported
    e.g.
    Code:
    SELECT
        SUM(CASE WHEN purchase_date BETWEEN '2004-08-01' and   '2004-08-31' THEN amount ELSE 0 END) As m2004_08,
        SUM(CASE WHEN purchase_date BETWEEN '2004-09-01' and   '2004-09-30'  THEN amount ELSE 0 END) As m2004_09,
        SUM(CASE WHEN purchase_date BETWEEN '2004-10-01' and   '2004-10-31' THEN amount ELSE 0 END) As m2004_10
    FROM purchases

    your split logic sounds like a great idea Dave thanks
    I am trying to produce this statement:
    SUM(case when mks_clienttype ='C' and mks_reason4fail in ("",'pri record found') then clients end) as Client_email
    variable     clientTypeFlag
    code     =If([Mks Clienttype] = "C") Then 1 Else 0
    variable     reason4failFlag1
    code     =If([Mks Reason4fail(trim)] = "pri record found" Or [Mks Reason4fail(trim)] = "") Then 1 Else 0
    variable     clientEmail
    code              ?
    how to actually get the sum of both clientTypeFlag and reason4failFlag1? I am trying to figure it out with no luck I have tried this:
    variable: ClientEmail1
    code: =Sum([clientTypeFlag]) Where ([clientTypeFlag] = 1)
    variable: ClientEmail2
    code: =Sum([clientTypeFlag]) Where ([reason4failFlag1] = 1)
    variable: clientEmail
    code: =[ClientEmail1] + [ClientEmail2]
    want the end result to look like this:
    Name  |  clientemail
    john      |           5
    bob       |           3
    jo          |           2
    Edited by: Dennis Alishah on Sep 21, 2010 5:58 AM

  • Need a pseudo cross tab query

    Not sure how to do this. I have a table with contents as
    empid
    empnm
    office
    phone
    and another table with
    empid
    workdt
    notin
    I need to display the data such as
    empid empnm office phone 1/1/12 1/2/12 1/3/12 1/4/12 1/5/12 1/6/12 1/7/12
    123 joe 123 x x x
    467 sam 333
    777 bill 444 x x
    The data in the employee file looks like this
    empid empnm office phone
    123 joe 123
    467 sam 333
    777 bill 444
    The data in the workdates file looks like this
    empid workdt notin
    123 1/1/12 x
    123 1/2/12
    123 1/3/12 x
    123 1/4/12 x
    123 1/5/12
    123 1/6/12
    123 1/7/12
    467 1/1/12
    467 1/2/12
    467 1/3/12
    467 1/4/12
    467 1/5/12
    467 1/6/12
    467 1/7/12
    777 1/1/12
    777 1/2/12 x
    777 1/3/12
    777 1/4/12
    777 1/5/12 x
    777 1/6/12
    777 1/7/12

    Hi,
    There are more different options but I show two below:
    with empdef as
    select 123 empid, 'Joe' empnm,  '123' office, cast(null as varchar2(10)) phone from dual union all
    select 467,       'Sam',        '333',        null from dual union all
    select 777,       'Bill',       '444',        null from dual
    ,workdata as
    select 123 empid, to_date('01-JAN-12', 'dd-mon-yy') workdt,  'X' notin from dual union all
    select 123, to_date('02-JAN-12', 'dd-mon-yy'),null from dual union all
    select 123, to_date('03-JAN-12', 'dd-mon-yy'),'X' from dual union all
    select 123, to_date('04-JAN-12', 'dd-mon-yy'),'X' from dual union all
    select 123, to_date('05-JAN-12', 'dd-mon-yy'),null from dual union all
    select 123, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all
    select 123, to_date('07-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('01-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('02-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('03-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('04-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('05-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('07-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('01-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('02-JAN-12', 'dd-mon-yy'),'X' from dual union all
    select 777, to_date('03-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('04-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('05-JAN-12', 'dd-mon-yy'),'X' from dual union all
    select 777, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('07-JAN-12', 'dd-mon-yy'),null from dual
    select
      e.empid
      ,e.empnm
      ,e.office
      ,e.phone
      ,max(case when w.workdt = to_date('01-01-2012', 'dd-mm-yyyy') then notin else null end) "1/1/12"
      ,max(case when w.workdt = to_date('02-01-2012', 'dd-mm-yyyy') then notin else null end) "1/2/12"
      ,max(case when w.workdt = to_date('03-01-2012', 'dd-mm-yyyy') then notin else null end) "1/3/12"
      ,max(case when w.workdt = to_date('04-01-2012', 'dd-mm-yyyy') then notin else null end) "1/4/12"
      ,max(case when w.workdt = to_date('05-01-2012', 'dd-mm-yyyy') then notin else null end) "1/5/12"
      ,max(case when w.workdt = to_date('06-01-2012', 'dd-mm-yyyy') then notin else null end) "1/6/12"
      ,max(case when w.workdt = to_date('07-01-2012', 'dd-mm-yyyy') then notin else null end) "1/7/12"
    from
      empdef        e     join
      workdata     w     on (e.empid     = w.empid)
    group by
      e.empid
      ,e.empnm
      ,e.office
      ,e.phone
    order by
      e.empid
    EMPID EMPNM OFFICE PHONE      1/1/12 1/2/12 1/3/12 1/4/12 1/5/12 1/6/12 1/7/12
      123 Joe   123               X             X      X                          
      467 Sam   333                                                               
      777 Bill  444                      X                    X                    or with the pivot clause:
    with empdef as
    select 123 empid, 'Joe' empnm,  '123' office,  cast(null as varchar2(10)) phone from dual union all
    select 467,       'Sam',        '333',        null from dual union all
    select 777,       'Bill',       '444',        null from dual
    ,workdata as
    select 123 empid, to_date('01-JAN-12', 'dd-mon-yy') workdt,  'X' notin from dual union all
    select 123, to_date('02-JAN-12', 'dd-mon-yy'),null from dual union all
    select 123, to_date('03-JAN-12', 'dd-mon-yy'),'X' from dual union all
    select 123, to_date('04-JAN-12', 'dd-mon-yy'),'X' from dual union all
    select 123, to_date('05-JAN-12', 'dd-mon-yy'),null from dual union all
    select 123, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all
    select 123, to_date('07-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('01-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('02-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('03-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('04-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('05-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all
    select 467, to_date('07-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('01-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('02-JAN-12', 'dd-mon-yy'),'X' from dual union all
    select 777, to_date('03-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('04-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('05-JAN-12', 'dd-mon-yy'),'X' from dual union all
    select 777, to_date('06-JAN-12', 'dd-mon-yy'),null from dual union all
    select 777, to_date('07-JAN-12', 'dd-mon-yy'),null from dual
    select
    from
      empdef        e     join
      workdata      w     using (empid)
    pivot(max(notin) for workdt in (to_date( '01-01-2012', 'mm-dd-yyyy') as "1/1/12"
                                    ,to_date( '01-02-2012', 'mm-dd-yyyy') as "1/2/12"
                                    ,to_date( '01-03-2012', 'mm-dd-yyyy') as "1/3/12"
                                    ,to_date( '01-04-2012', 'mm-dd-yyyy') as "1/4/12"
                                    ,to_date( '01-05-2012', 'mm-dd-yyyy') as "1/5/12"
                                    ,to_date( '01-06-2012', 'mm-dd-yyyy') as "1/6/12"
                                    ,to_date( '01-07-2012', 'mm-dd-yyyy') as "1/7/12"
    EMPID EMPNM OFFICE PHONE      1/1/12 1/2/12 1/3/12 1/4/12 1/5/12 1/6/12 1/7/12
      467 Sam   333                                                               
      123 Joe   123               X             X      X                          
      777 Bill  444                      X                    X                    Regards,
    Peter

  • CROSS TAB PRINTING IN PDF PROBLEM

    Post Author: peachpx
    CA Forum: General
    Hi,
    My report uses a Cross Tab query with multiple lines for each value. Originally, I only get one line for Total In.  I modified Total In to include three lines Total Into Final, Total Into Initial and Total Out.  It displays fine in the report, but when I try to print from the server it opens PDF file with only one line present Total Into Final and the other two lines are cut off.  Is this a BUG in CRXII or is this can be fixed with correct formatting?
    Please help!

    Hi,
    cross tab is a diagonal report , u have to make query in such a way so that it returns the all field in row and columns way  i.e in diagonal form .
    U have to fetch total in same manner
    Rgds,
    Premraj

  • Oracle Cross Tabs

    Hi peers,
    i am really stack on how to do the following using Oracle SQL. I want to build a cross tab query where my columns are current year& next year months ( i.e 24 columns will be built)..
    any thoughts on how to do that ?
    thank you

    Hi sb92075 ,
    i got it i am trying to see how can i tweak it lit bit..
    in my case i have a cross tab query were values in my SELECT statment are different , example :
    SELECT *
    FROM
    SELECT
    PROJECTNAME,
    PROJECTID
    SUM(DECODE(to_char(IM_MONTH,'mm-yyyy'), to_char(add_months(sysdate,1),'mm-yyyy'), SALE,0)) as '01-2011'
    ,SUM(DECODE(to_char(IM_MONTH,'mm-yyyy'), to_char(add_months(sysdate,2),'mm-yyyy'), SALE,0)) as '02-2011'
    ,SUM(DECODE(to_char(IM_MONTH,'mm-yyyy'), to_char(add_months(sysdate,3),'mm-yyyy'), SALE,0)) as '03-2011'
    FROM TABLE
    what i am looking for is :
    1-
    to have (sysdate,1) replaced by the 1st month of the current year 'JAN-2011'
    same thing for (sysdate,2) replaced by the 1st month of the current year 'FEB-2011'
    and so on until the last month of the next year . In total 24 monthss
    2-
    for each select item , i need to have the column called by that month name i.e :
    SUM(DECODE(to_char(IM_MONTH,'mm-yyyy'), to_char(add_months(month1),'mm-yyyy'), SALE,0)) as 'month1'
    SUM(DECODE(to_char(IM_MONTH,'mm-yyyy'), to_char(add_months(month2),'mm-yyyy'), SALE,0)) as 'month2'
    any thoughts ?
    thanks

  • Cross-tab style queries...

    As you may have guessed, I'm new to the Oracle flavour of SQL.
    I'm trying to create a cross-tab query, do any of you guys know a good way of doing this?
    Thanks very much.

    You can do like this. Its an ex. you can extend as you need
    SELECT job,
    sum(decode(deptno,10,sal)) DEPT10,
    sum(decode(deptno,20,sal)) DEPT20,
    sum(decode(deptno,30,sal)) DEPT30,
    sum(decode(deptno,40,sal)) DEPT40
    FROM scott.emp
    GROUP BY job
    Hari

  • Cross tab in Oracle8i

    why access such a small database can provide cross tab query
    facility and not by oracle, if somebody knows the real and
    flexible method of doing this plz be informs us.I will be highly
    oblized
    thanks

    I came across this example recently on the site:
    http://www.onwe.co.za/frank/faqscrpt.htm
    I believe this is what you're looking for...
    rem -------------------------------------------------------------
    rem UPDATED VERSION
    rem Filename: matrix.sql
    rem Purpose: Example of a CROSS MATRIX report implemented
    using
    rem standard SQL.
    rem Date: 12-Feb-2000
    rem Author: Frank Naude ([email protected])
    rem
    rem Updated By Mahesh Pednekar. ([email protected])
    rem Description Removed the Main query because the sub query
    itself
    rem will full fill the requirement.
    rem -------------------------------------------------------------
    SELECT job,
    sum(decode(deptno,10,sal)) DEPT10,
    sum(decode(deptno,20,sal)) DEPT20,
    sum(decode(deptno,30,sal)) DEPT30,
    sum(decode(deptno,40,sal)) DEPT40
    FROM scott.emp
    GROUP BY job
    -- Sample output:
    -- JOB DEPT10 DEPT20 DEPT30 DEPT40
    -- ANALYST 6000
    -- CLERK 1300 1900 950
    -- MANAGER 2450 2975 2850
    -- PRESIDENT 5000
    -- SALESMAN 5600

  • Cross tab - to summarize number of rows

    Hi Everyone,
    a) I notice that if I use the count of Final Grade field, some students have more than one row for that class.
    So the count = 2.
    b) I created a calc: If Final Grade Count > 1, then set calc to 1.
    c) then I duplicated query as cross tab
    there are 2 datapoint fields: final grade count and Calc_RevisedCount
    d) delete final grade count and left Calc_RevisedCount
    e) dragged Course name to left,
    Final_Grade on top
    Calc_RevisedCount is the datapoint
    f) problem is that the calc_REvisedCount is NOT tabulating/summarizing
    the boxes are being populated with 1's
    Is there a better approach, or do you have any advice? thx in advance, sandra

    Hi Rod,
    tx for writing...
    a) Do you mean I should create a calc?
    b) Do I use plain Count_distinct (or the version with partition)
    c) I can use a calc as a data point in a cross tab query?
    i'm going home for the day.... tx soooo much for writing back..... sandra

  • Dynamically color to each column in Cross-tab report

    Hello All,
    I am a newbie in Crystal report,from last few weeks, i am working on cross tab crystal report.i have a requirement to show color dynamically for each column.i am adding an attachment how i want it. i tried dynamic coloring using object field formula but it is showing red color to all data.i want red color data when in 2nd  cross tab report data is beyond upper or lower limit in first cross tab table. it will be very helpful if somebody will give me any clue on this.... i read so many articles now it seem like impossible for me..:(
    i am using visual studio 2010 and sap crystal report version 13.0.0.99 for visual studio 2010.

    Hello Manish,
    I have attached a sample report that does this. You will need to remove the .txt extension from the attached file to open it as an .rpt file.
    Please right click on one of the value fields of the first cross tab in the report > Format Field > Common > Suppress if Duplicated conditional formula.
    The nested formula is as follows;
    numbervar array l;
    numbervar array u;
    numbervar x:=CurrentColumnIndex;
    if GridRowColumnValue ('@limit') = 'lower limit' then
    (redim preserve l[x];
    l[x]:= tonumber(CurrentFieldValue))
    else if GridRowColumnValue ('@limit') = 'upper limit' then
    (redim preserve u[x];
    u[x]:= tonumber(CurrentFieldValue));
    false
    So it assigns each lower and upper limit value for each client (in the sample it is country) to an array using the cross tabs column index to index the array and it ends in False as we don't actually want it to suppress if duplicated. This nested formula is just used to generate the arrays of upper and lower values.
    In the second cross tab if you again right click on one of the value fields > Format Field > Font > Color you will see the following conditional formula;
    numbervar array l;
    numbervar array u;
    numbervar x;
    if not(tonumber(CurrentFieldValue) in l[CurrentColumnIndex] to u[CurrentColumnIndex]) then
    crred
    else
    crblack
    So this compaes the current field value to range generated by the 2 arrays and assigns a color based on whether or not it is in the range.
    Regards,
    Graham

  • Creation of cross tab report in Bw 3.5 Query designer

    Hi,
      Please tell me the procedure to create cross tab report in BW 3.5 Query designer. Kindly reply as early as possible.
    Regards,
    Hari Phrased B.

    Hi,
    What exactly do you mean by "cross tab report"...do you mean a web report with different tabs?

  • Dynamic sorting in Cross Tab Report

    I have 2 cross tabs in a report with element linking that filters data in 2nd report when I click on values in the first. I'd like a way to be able to sort the results in the 2nd cross tab in ascending or descending order dynamically.
    Please see image below (click image for better quality) for a detailed representation of the problem.
    Is this possible?

    Right click on crosstab and go to Crosstab Expert and in the columns click on "group options" button and in the options tab select "Use a formula as sort order" and write the condition like this
    if {?Parameter}="Ascending" then
    crAscendingOrder
    else
    crDescendingOrder
    Hope this helps!
    Raghavendra

Maybe you are looking for

  • HTML tags in RTF--- Urgent pls help

    i have a field in answers with the name comments which returns the data in html tags like <~a>abcd <~/a>, it has to dispaly as a link but it is displying as <~a>abcd</~a> the same with html tags in it... how can i parse the HTML tags in BI publisher,

  • After install SXDE 1/08 don't start

    Hi! I have install SXDE 1/08, but after start system halt after GRUB window. When I select safe mode - system start ok.

  • Join in Complex Folder

    Is it possible to do a join when building a custom folder? According to the training books the SQL supported in custom folders is limited. It seems like every corner I turn in discoverer I run into a limitation.

  • Soundbooth error when I try to record - WinFile.cpp-705

    We are using Soundbooth on a high school classroom computer. When we try to record from a microphone we get the following error message: ..\..\Src\Win\WinFile.ccp-705 Does anyone know what is causing this error? The permission rights on school comput

  • Writing through TEXT_IO

    Dear Gurus I am using Forms 10G. I am using Text_io to read the text file and putting into table and again reading the tables and putting into another text file . But when i am reading from table the out put file is coming like this :- 0|82374628|abc