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
Similar Messages
-
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
SandeepFrank,
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 -
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.
*/ -
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,
xtantoSearch this forum for "pivot". Plenty of examples.
Regards,
Rob. -
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 helpuser1849 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 -
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)
nullHi 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 -
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 purchasesyour 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 -
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 youHi 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 reporting in Crystal 8.5
Post Author: KPetrey
CA Forum: General
I am trying to create a cross tab report for some data that will have varying number of columns.I am running into a problem where some situations are producing 25 or more columns. This results in the crossing over to a second page.My end-users are going to dislike this very much. I am trying to duplicate a report they had with their previous software system and it did not cross pages. All data stayed on one page. My questions are as follows:Is there a way to make the cross tab wrap so that data does not cross to second page?Is there a different way to do what I need other than cross tab?What I am trying to do is list a column for each store that will show the qty of a product that is ordered for it....the number of stores will vary depending on my end-users setup. Any help would be greatly appreciated.ThanksPost Author: wapper
CA Forum: General
Crosstab is designed to grow wide-wise if the number of columns increases. How can you avoid splitting pages if the number of columns will reach, for example, 50?
You should probably first make a decision, whether your report must be fixed-column or variable-column. If you stick to fix-column, you can design the report to accommodate theoretical maximum of columns, and imitate dynamic columns by using groups, formulas and hiding columns not in use at run time. Pain in the a** with 25+ columns but still doable. Drawback - if actual data will exceed the maximum number of columns, you are out of luck. Or you could stay with crosstab to keep support for variable number of columns, using small font and "Show Cell Margins" option to squeeze as many columns as is actually possible before falling over to the second page. I would prefer the latter if you ask me.
Wapper -
Dynamic or cross tab report in sap
Dear Gurus,
I want to develop a report in SAP where colums will be variable like if data increase colume will also be increased.I am giving an example below which clarify my requirements : -
In normal ALV display as follows :-
Material Batch Month Qty
M1 B1 04-2011 10.00
M1 B1 05-2011 15.00
M1 B1 06-2011 8.00
M2 B6 05-2011 18.00
M2 B6 06-2011 30.00
M3 B5 07-2011 35.00
I need this like following :
Material Batch 04-2011 05-2011 06-2011 07-2011
M1 B1 10.00 15.00 8.00 0.00
M2 B6 0.00 18.00 30.00 0.00
M3 B5 0.00 0.00 0.00 35.00
Here if month increase then it will increase like that :
Material Batch 04-2011 05-2011 06-2011 07-2011 08-2011
M1 B1 10.00 15.00 8.00 0.00 1.00
M2 B6 0.00 18.00 30.00 0.00 2.00
M3 B5 0.00 0.00 0.00 35.00 58.00
It can be increased upto n no of entries depends on selection screen.
I have never develop such type of report .Please help me out to develop this report.
Advance Thanks
Nirmal Sharma
Moderator message: please don't just post the same thing again after the previous one was locked by moderators.
Edited by: Thomas Zloch on Aug 12, 2011 2:26 PMplease refer the below thread.. i am sure you will find the solution.... its not difficult at all.
Need Dynamic or Cross tab reports -
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 -
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
thanksI 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 -
Post Author: ivanl
CA Forum: Formula
Hi,
Using XI and win XP.
I have been using excel to get the info I need, but thought it must be possible to do it right in the cross tab. I need two different cross tabs, and do not know how to do the following.
The fields I have in the dataset include:
- product.type (different products and one field "product.type = 'customer' that is the customers)
- product.balance (balance of each product for each customer)
- formula for age segmentation
What I need to input into the cross tab is to have the segmentation across the top, products for the rows and as the summary:
1) penetration rate (i.e. count of product types divided by # of customers which is product.type = customer)
2) $ per customer (product balance divided by customers)
3) $ per product (product balance divided by # of products)
Help would be awesome. I have no idea how to do this in Crystal
To date, I have set up a cross tab with segment across top, products down the rows, and as a summary using count products and sum of balances. I would input this into excel and do the calculations.
IvanHi, this may help,
http://www.chelseatech.co.nz/pubs.htm
Look down on the right side, you should see
Sample Report Files
Sales Calendar
Calendar Report
Running Totals in a Crosstab
Wrapping Crosstab
PDF Drill Down
Crosstab calculations
Hierarchical Summary in a formula
You can download an example of Crosstab Calulations from this site.
They have some newsletters that also contain CR hints. -
Crystal Reports Cross-Tab Report not showing all available fields
I am running CR2008 against MS SQL Express. I have several tables with fields and data in them and can create standard reports to show all the data in all the fields. However, when I try to create a cross-tab report, only some of the fields appear for me to choose from.
I created a standard report with all the fields I needed in my cross-tab report and ran a preview. Everything was there. I then added a cross-tab object, selected the tables only to find that fields that are in the main report are not showing up for selection in the cross-tab.UPDATE: I exported the entire database from MS SQLExpress to MS Access and I am having the same issues, so it does not appear to be a problem with the database engine and, since the standard tabular reports show the fields, I am at a loss as to why they don't show up in the cross-tab or the Parameter fields.
I am creating the cross-tab through the Cross-Tab wizard. Is there maybe a bug in that? Is there a way to create it otherwise?
Maybe you are looking for
-
Need a Exit or BADI For Changing Validation Class (PRUEFKL) during EL28
need to change the Validation Class Validation Class (PRUEFKL) or send it blank in order to remove all valdition during Meter read uplaod , Can any one suggest a BADI or user exit or anything where in i can change the Validtion class before valida
-
How do I change a pdf document to word
How do I change a pdf document to a word document
-
How I got ActiveSync/Exchange to work with Iphone3G
So, to the point. First, my setup: Windows SBS 2003, Exchange 2003 SP2, default website in IIS is secured by a 3rd party (geotrust) certificate. Second: My initial attempts I started off by tapping into the iphone the various details it asks for in t
-
Hi! How to change settings to Facebook app in my Nokia C7? It shows mainly game notifications from my friends, which I don't want to see. When using Facebook by PC, I have settings so that it doesn't show those notifications.
-
Adobe Flash Player Actionscript errors
I keep getting these pop up error messages. I did some research and see that my computer (new) may be running the "debugging" version. As Adobe Flash Player is embedded in Windows 8.1 (to which I am a new user of), I can't figure out how to change