Reputation: 1388
I have to generate a report in Crystal report and VB report where database is Oracle, like the attached screen shot:
I have used the following query and got the output as below screen shot:
SELECT ins.ins, ins.ins_name, crdi.ct, crdi.bin,
(select count(*) from crdh where crd_st='CN') as CNcount, (select count(*)
from crdh where crd_st='PO') as POcount
FROM crdh, crdi, ins
where crdh.bn=crdi.bn and crdi.ins=ins.ins and crdh.crd_st IN ('PO','CN')
GROUP BY ins.ins, crdi.bn, ins.ins_name,crdi
ORDER BY ins.ins, crdi.bn;
I have the following issues:
I ran the following query and got the output as below screen shot
SELECT ins.ins_name,ins.ins,
crdi.crd_st, crdi.bin, crdh.crd_st,
COUNT(crdh.crd_st) as count
FROM crdh, crdi, ins
WHERE crdh.crd_st IN ('PO','CN') and crdi.bn in
(select unique bn from crdh)and crdh.bn=crdi.bn and
crdi.ins=ins.ins
GROUP BY ins.ins, crdi.bn, ins.ins_name,
crdi.crd_st,crdh.crd_st
ORDER BY ins.ins, crdi.bn;
I want to show the count column as a row in the report for respective bn.
I have Oracle 10g database and followed the following link
And make the following query and got the 'ORA-00933: SQL command not properly ended' error.
SELECT bn, CNCount, POCount
FROM (
SELECT bn,
crd_st,
ROW_NUMBER() OVER (PARTITION BY bn ORDER BY crd_st) AS cardRank
FROM cardholder
)
pivot( count(crd_st) FOR cardRank IN ('CN' as CNCount, 'PO' as POCount));
Thanks for your help in advance.
Upvotes: 1
Views: 1901
Reputation: 1388
I got the required output by running the following query:
SELECT ins.ins_name,ins.ins,crdi.ct, crdi.bn,
sum(DECODE(cardh.crd_st, 'PO', 1, 0)) POCount,
sum(DECODE(cardh.crd_st, 'CN', 1, 0)) CNCount
FROM crdh, crdi, ins
WHERE crdh.crd_st IN ('PO','CN') and crdi.bn in
(select unique bn from crdh)and crdh.bn=crdi.bn and
crdi.ins=ins.ins
GROUP BY ins.ins, crdi.bn, ins.ins_name,crdi.ct
ORDER BY ins.ins, crdi.bn;
Upvotes: 1
Reputation: 9101
Since you got some output, now to manuplate that output as required use cross tab in crystal report.
bn
in column.@Count
and write just "Count"
in that formula and use the formula in rows.Count
in summarized fields.Let me know how it goes
Edit--------------------------------------------------------------------------------------
1. Drag the crosstab on to report.
2. `Right click` on crosstab and go to `Crosstab expert`
3. There you will find 3 options, `Rows`, `Columns` and `Summarized fileds`
4. place the field what you want in row, place the filed what you want in column and same way place the column for summarized fields
Upvotes: 1