Cross Tab Sql Query
I have two tables
Tab1
Lookup Code
Lookup Type
Description
Tab 2
Bureau code
member code
partner code
x
y
z
My requirment is a bit typical (i guess)
Tab1
lookupcode lookup type desc
TRA Bureau code Sample Desc1
CCHK Membder Code Sample Desc2
CMSI Partner Code Sample Desc3
TAB2
Bureau Code Member Code Partner Code x y z
TRA CCHK CMSI 1 2 3
i want the data to be fetched in this fashion
x y z DESC1 DESC2 DESC3
1 2 3 Sample Desc1 Sample Desc2 Sample Desc3
How can i get the description of respective Lookup codes from tab1
while querying tab2.
I fell pivoting the table can do this but unable to frame the query properly
Please help me on this
Thanks in Advance
select x,y,z
, (select "lookup type" from tab1 b where b.lookupcode=a."Bureau Code") Bcode
, (select "lookup type" from tab1 b where b.lookupcode=a."Member Code") Mcode
, (select "lookup type" from tab1 b where b.lookupcode=a."Partner Code ") pcode
from tab2 a;
Similar Messages
-
hi all , im a beginner in SQL and just discovering oracle and Java so i made a small database : 1 table
and i did the Database connectivity with my platform Java ( Netbeans) and every thing was okay.
i started looking for how to create a cross tab between 2 elements from my table but i couldn't find the SQL script to do it
my table is :
ID--NAME--SURNAME--LOCATION---GRADE
i want to have a cross tab between locations and the grade which calculatin the count of ID in each field so to create the interface in java so any help plz
i know its somethin classic but im just a new beginner and im trying to create a simple database application
i USE ORACLE 10G XE and NETBEANS
thnxxHello,
welcome to the Oracle forums. This is the forum for the tool "SQL Developer". Questions about SQL and PL/SQL have their own forum at PL/SQL
Best Regards
Marcus -
Hi,
I am using oracle 11g version.
I have a reporting requirement where in I have to produce a cross tab as explained below. Please help me in writing an SQL query to achieve this. Many thanks.
Sample data:
Customer product type
AAA DVD
AAA Tape
BBB Tape
CCC DVD
CCC Bluray
DDD DVD
DDD Tape
DDD Bluray
Logic
AAA BBB CCC DDD
DVD Tape Bluray DVD Tape Bluray DVD Tape Bluray DVD Tape Bluray
DVD 1 DVD DVD 1 DVD 1
Tape 1 Tape 1 Tape Tape 1 1
Bluray Bluray Bluray 1 Bluray 1 Final Output
No. of customers who purchased the products across all product types
DVD Tape Bluray
DVD 2 1
Tape 2 1 1
Bluray 1 1
Scripts:
create table cust_product(customer varchar2(5), product_type varchar2(10));
insert into cust_product values('AAA','DVD');
insert into cust_product values('AAA','Tape');
insert into cust_product values('BBB','Tape');
insert into cust_product values('CCC','DVD');
insert into cust_product values('CCC','Bluray');
insert into cust_product values('DDD','DVD');
insert into cust_product values('DDD','Tape');
insert into cust_product values('DDD','Bluray');Hi,
858747 wrote:
... Sample data:
Customer product type
AAA DVD
AAA Tape
BBB Tape
CCC DVD
CCC Bluray
DDD DVD
DDD Tape
DDD Bluray...
Final Output
No. of customers who purchased the products across all product types
` DVD Tape Bluray
DVD 2 1
Tape 2 1 1
Bluray 1 1
Sorry, I don't follow the logic. Try explaining in words, with specific examples.
Didn't 2 distinct customers, 'CCC' and 'DDD', buy both 'DVD' and 'Bluray'? Why aren't the results
` DVD Tape Bluray
DVD 2 2
Tape 2 1 1
Bluray 2 1 with 2's in the corners?
Assuming that was just mistake, you can do something like this:
WITH got_pairs AS
SELECT a.product_type AS product_a
, NVL (b.product_type, a.product_type) AS product_b
FROM cust_product a
LEFT OUTER JOIN cust_product b ON a.customer = b.customer
AND a.product_type != b.product_type
SELECT *
FROM got_pairs
PIVOT ( COUNT (*)
FOR product_b
IN ( 'DVD'
, 'Tape'
, 'Blueray'
ORDER BY CASE product_a
WHEN 'DVD' THEN 1
WHEN 'Tape' THEN 2
WHEN 'Bluray' THEN 3
END
;This assumes that the combination (customer, product_type) is unique, as it is in your sample data., and that the only product_types are the 3 in your sample data.
if those assumptions are not true, then post some revised sample data and results, that show what you want in those cases.
Sorry, I don't have an Oracle 11 database right now to test this.
I can (and did) test the outer join, that combines a product_type with itself only if it can't be combined with anything else.
Using a pre-Oracle 11 pivot technique, the following works:
WITH got_pairs AS
SELECT a.product_type AS product_a
, NVL (b.product_type, a.product_type) AS product_b
FROM cust_product a
LEFT OUTER JOIN cust_product b ON a.customer = b.customer
AND a.product_type != b.product_type
SELECT product_a AS product_type
, COUNT (CASE WHEN product_b = 'DVD' THEN 1 END) AS dvd
, COUNT (CASE WHEN product_b = 'Tape' THEN 1 END) AS dvd
, COUNT (CASE WHEN product_b = 'Bluray' THEN 1 END) AS dvd
FROM got_pairs
GROUP BY product_a
ORDER BY CASE product_a
WHEN 'DVD' THEN 1
WHEN 'Tape' THEN 2
WHEN 'Bluray' THEN 3
END
;Notice that the sub-query got_pairs is the same in both queries.
Thanks for posting the CREATE TABLE and INSERT statements; that's very helpful!
Edited by: Frank Kulash on May 29, 2011 4:05 PM
Added Oracle 9 query. -
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.
*/ -
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 -
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? -
How create SQL for Cross tab in template
Hi,
I have been starting to build data templates using SQL to select the data I require. I noticed in the word template-building tool there is an option to create cross tab table. I have tried looking at the standard documentation. I have been unable to work out how I should structure the SQL in my data template to allow me to create a cross tab table in the template?
Thanks,
MarkPost Author: SunilKanta
CA Forum: General
Yes, I had done exactly the same but when tried to display the subreport in new page, some portion of the cross tab is displayed. The page width is not increased proportionately.
i have passed that sub report in footer of main report.
But when i overlap this sub report with other cross tabs already present in the main report i can see full width view of sub report. -
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. -
How does one have a recursive query in a cross-tab report?
I am trying to build a report off of a table much like an accounting transaction log where a subsequent (payment) transaction points to a previous (charge) transaction on the same table. Most of the data I need to display is off of the payment transaction but the column header in the cross-tab needs to pull off of the initial, charge transaction (the data is not stamped on the payment transaction).
Whenever I add the second instance of the table to my report (as the column label) my summary data is doubled or worse. I have tried to create a calculated field to filter and hopefully only sum up the payment transactions and use the calculated field as the summary data field but that is not affecting the totals.
The truly odd thing about this is the summary field on the charge transaction does not contain any data, only the payment transactions have data in this field so the sum totals should be correct despite the double pull from the table.
How can I read data from related records on the same table without affecting the sum totals?
Any guidance would be appreciated!! Thanks!Please re-post if this is still an issue and add a lot more info
-
Discoverer Report showing Null VS Show SQL query showing results !!!
I created a simple Cross Tab Discoverer report from a custom SQL which has a calculation for balances. The output is giving all null values even though there are balances. The output doesn't seem right. So I copied the query from Tools-->Show SQL and ran the query in the TOAD where I'm showing balances for the report. I don't understand why it is not showing in the discoverer. Please help.
Thanks
Edited by: PA1B on Jan 27, 2010 11:40 AMSorry for late reply.
Below is the Show SQL query. I don't think the query is application dependent. C_1 is my calculation.
SELECT o279709.SEGMENT3 as E279727,
o279709.SEGMENT4 as E279728,
CASE WHEN o279709.CURRENCY_CODE = 'USD' AND o279709.TRANSLATED_FLAG <> 'Y' THEN SUM(o279709.ENDING_BAL) ELSE 0 END as C_1,
GROUPING_ID(o279709.CURRENCY_CODE,o279709.SEGMENT3,o279709.SEGMENT4,o279709.TRANSLATED_FLAG) as GID
FROM ( --Foriegn Entity USD Balances
SELECT B.SEGMENT1,
B.SEGMENT2,
B.SEGMENT3,
(select distinct substr(cat.COMPILED_VALUE_ATTRIBUTES,5,1) from apps.fnd_flex_values cat
where FLEX_VALUE_SET_ID = (select bat.FLEX_VALUE_SET_ID from apps.fnd_id_flex_structures_vl aat, apps.fnd_id_flex_segments_vl bat
where bat.id_flex_code = 'GL#' and
bat.id_flex_code = aat.id_flex_code and
aat.APPLICATION_ID = bat.APPLICATION_ID and
aat.APPLICATION_ID = 101 and
bat.SEGMENT_NAME = 'Prime Account' and
aat.id_flex_num = bat.id_flex_num
and bat.id_flex_num in (select distinct chart_of_accounts_id from apps.gl_code_combinations gat
where gat.code_combination_id = A.code_combination_id))
and cat.flex_value = b.segment3) ACCT_TYPE ,
B.SEGMENT4,
B.SEGMENT5,
B.SEGMENT6,
B.SEGMENT7,
B.SEGMENT8,
B.SEGMENT9,
B.SEGMENT10,
B.SEGMENT11,
B.SEGMENT12,
B.SEGMENT13,
C.NAME,
A.SET_OF_BOOKS_ID,
A.CURRENCY_CODE,A.TRANSLATED_FLAG,
SUM(NVL(A.BEGIN_BALANCE_DR,0) - NVL(A.BEGIN_BALANCE_CR,0)) BEG_BAL,
SUM(NVL(A.PERIOD_NET_DR,0)) DEBITS,
SUM( NVL(A.PERIOD_NET_CR,0)) CREDITS ,
A.PERIOD_NAME,
SUM(NVL(A.BEGIN_BALANCE_DR,0) - NVL(A.BEGIN_BALANCE_CR,0))+ SUM(NVL(A.PERIOD_NET_DR,0) - NVL(A.PERIOD_NET_CR,0)) ENDING_BAL
FROM APPS.GL_BALANCES A ,
APPS.GL_CODE_COMBINATIONS B,
APPS.GL_SETS_OF_BOOKS C
WHERE A.CODE_COMBINATION_ID = B.CODE_COMBINATION_ID
--AND A.PERIOD_NAME = 'SEP-09'
AND C.SET_OF_BOOKS_ID = A.SET_OF_BOOKS_ID
--AND A.TRANSLATED_FLAG <> 'Y'
--AND B.SEGMENT1 = '83101'
--AND B.SEGMENT3 = '14602'
--AND A.SET_OF_BOOKS_ID = 77
--AND A.CURRENCY_CODE = 'USD'
GROUP BY A.CODE_COMBINATION_ID,
B.SEGMENT1,
B.SEGMENT2,
B.SEGMENT3,
B.SEGMENT4,
B.SEGMENT5,
B.SEGMENT6,
B.SEGMENT7,
B.SEGMENT8,
B.SEGMENT9,
B.SEGMENT10,
B.SEGMENT11,
B.SEGMENT12,
B.SEGMENT13,
A.CURRENCY_CODE,
A.TRANSLATED_FLAG,
C.NAME,A.PERIOD_NAME,
A.SET_OF_BOOKS_ID
) o279709
WHERE (o279709.PERIOD_NAME = 'DEC-09')
AND (o279709.SET_OF_BOOKS_ID <> 72)
AND (o279709.SEGMENT12 = '000')
AND (o279709.SEGMENT3 IN ('10101','10301','10502','12001'))
AND (o279709.SEGMENT1 IN ('82901','82902','82903','83001','83003','83201'))
GROUP BY GROUPING SETS(( o279709.CURRENCY_CODE,o279709.SEGMENT3,o279709.SEGMENT4,o279709.TRANSLATED_FLAG ),( o279709.SEGMENT3,o279709.SEGMENT4 ),( o279709.SEGMENT3 ))
HAVING (GROUP_ID()=0)
ORDER BY GID DESC;
Thanks,
PA1
Edited by: PA1B on Jan 29, 2010 12:50 PM -
How to create a Matrix table using this data in SQL Query Analyzer
Hello all,
I have a problem while I am trying to represent my Sql Table namely table1 in Matrix form
my table Format is
city1 city2 Distance--------------------------------------------------------
Mumbai Delhi 100
Delhi Banaras 50
Mumbai Rajasthan 70
Banaras haryana 40
Mumbai Mumbai 0
784 entries
there are 784 cities each having link to other
Now i want my output as
Mumbai Delhi Banaras haryana
Mumbai 0 100 -- --
Delhi 100 0 50 --
Banaras
haryana
respective distance from one city to other should be shown
final Matrix would be 784*784
I am using SQL Query Analyser for this
Please help me in this regardI'm pretty much certain that you don't want to do this in pure SQL. So that means that you want to do it with a reporting tool. I'm not familiar with SQL Query Analyzer, but if it is in fact a reporting tool you'll want to consult its documentation looking for the terms "pivot" or perhaps "cross tab."
-
Field value retrieve from sql query
Hi,
Is there any way to code sql query into form field in rtf template ?.
I have converted an oracle report to BI publisher (e-business suite R12) but I have a form field that contain a sql query that retrieve a value from database. I don't know how to code sql query in form field in rtf template.
Thanks for help,http://winrichman.blogspot.com/search/label/cross%20tab
http://winrichman.blogspot.com/search/label/Cross-tab
http://winrichman.blogspot.com/search/label/Dynamic%20column -
Record selection issue in cross tab.
Hello!
I have a record filtering problem. I tried many scenarios, and searched this forum but I cannot find an solution.
I have a sub-report that contains a cross tab that provides a few summarized fields.
I have two tables: a table with category of events : (field catID and Catname) and an event table with a CatID, a date field and others number field I use in the cross tab.
I want my cross tab to show one row per category. The Catname and the summaries.
Now all is working fine but for one issue. I need to select my event according to a time bracket.
So I created two time parameters (start and end) and select the event dates between these two dates.
Now, when selected, any category that does not have an event between these dates are not displayed. I would like them to be shown with "o" values.
There must be a way of doing this. I just cannot find it.
EstherIn order for Crystal to show data, it must be given data to show!
You will need to base your subreport on an SQL Command. In that command, put the current SQL used by the report. To this, do a UNION to a select that selects the category name, and a zero for each field that you are summing in the crosstab.
As a simplified example, suppose the original SQL was (MS SQL):
select c.catname, sum(e.quantity) as Quantity
from categories c, events e
where c.catid = {?catid parm}
and c.catid = e.catid
and e.date between {?start} and {?end}
This would be changed to
select c.catname, sum(e.quantity) as Quantity
from categories c, events e
where c.catid = {?catid parm}
and c.catid = e.catid
and e.date between {?start} and {?end}
UNION
select c.catname, 0 as Quantity
from categories c
where c.catid = {?catid parm}
This will return an additional zero record, regardless of what data the original query returns, thus giving Crystal the data needed to display. Note that the zero value will not affect the results in any way, except causing a zero to be displayed if no data is returned from the original query.
Just remember that the second SELECT in the UNION has to have the same number of fields, of the same data type, as the first SELECT.
HTH,
Carl -
SAP Web Intelligence -Comparing subsequent columns in cross tab
Hello,
I am new in SAP web intelligence , I need formula (Not a SQL Query) to find difference of values between subsequent columns in cross tab. Please find attached excel for more details
Thanks & RegardsTry something like in below screenshot-
Craete variable
Diff Amount2=Previous([Amount2])-[Amount2]
~Anuj -
Cross tab report-dyanamic columns for months and quarterly sum
Hi all,
I work on report creation in BI Publisher.I need to display values in a cross tab report in a way that it shows data for 3 months and then a column for its quarterly sum.
For ex:-
Market --Jan Feb Mar Q1_sum Apr May Jun Q2_sum ---------------like wise for n months
Market1 100 --80 --30 -- 210 --10 -- 80 --90 --210
Market2 120 --90 --40 --250 --100 --70 --30 --200
Market3 130 --70 --60 --260 --140 -- 0 --40 --180 ('--' just to maintain indentation)
The values of number of months( date range) and the names of market are derived dyanamically .
The code from my sql query presently shows months-range (Jan ,feb,mar..), Quarterly sum to be displayed, Market names etc as child elements in multiple occurences main Query set.
<Main Query>
<Market>abc</Market>
<Region>abc</Region>
<Months-Range>abc</Months-Range>
<Quarterly_sum>abc</Quarterly_sum>
<Main Query>
<Main Query>
</Main Query>
Please guide me on code in rtf template for the same.
Thanks
Edited by: user9061488 on Jul 13, 2010 1:32 AM
Edited by: user9061488 on Jul 13, 2010 3:48 AMHi,
Do u have time dim in your metadata??
If not,
Create a time dimension year,quater,month,day
http://lh4.ggpht.com/_rhCtHYLiamQ/S7PQvxYBbzI/AAAAAAABZXI/ef_Ur9AmyUo/s800/04_year_quarter_bmm.jpg
After that in fact table by using the (ago/todate) function ....pull the respective columns to pivot table columns section(date column) and measures col in measures section and enable the grand total in columns section so that it will show grand total for every quarter
thanks,
saichand.v
Maybe you are looking for
-
Dock settings not saved?
Hello. I'm on an OS X Server 1.0.4.11 on a PowerMac G4. I'm logged in as a user in the Administrators group, but my Dock's current settings are not being saved - when I login again, the dock reverts back to the items that I've removed and doesn't hav
-
Anyone has print out the iPhoto album book by apple after finish editing? May I check is the quality good? I have compiled my photo album book , choosen hard cover option , 100 pages , estimated cost is US150. Not sure worth to print out or not?
-
When I try to use the file I added to my library in illustrator, it gives me an error: Could not place the document '8d63df86-9954-4c5c-b49e-0c0255fd7d11.ai' because of a program error. Any idea what's wrong or how to resolve this?
-
SQL Server 2008R2 Active-Active cluster with standard edition?
Hi all, can I have a 2 node cluster (Windows Server 2008R2 Datacenter Edition: node_1 and node_2) forming a failover cluster with 2 instances of SQL Server 2008R2 Standard Edition (instance_A and instance_B) with: instance_A running on node_1 instanc
-
Accounting ( no cost)
Hi I have assigned WBS element in accounting tab in account assignment.The WBS element has the cost planning. However clicking the " calculate" button gives error" Internal error: Calling costing leads to exception". Where I am wrong.................