Search code examples
sqloraclevb6crystal-reports

Genrate a report in crystal report where count of a field put into a column


I have to generate a report in Crystal report and VB report where database is Oracle, like the attached screen shot:

enter image description here

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;

enter image description here

I have the following issues:

  1. How can I correct the above query so that it can return the count of crd_st for a perticular bn where crd_st is 'CN' or 'PO' separately. For example this query should tell me what is the count of records where crd_st is PO for bn 123456.
  2. I am very new in the Crystal report. Please help to make this report file and
  3. Also tell me how can I implement Sr No for numbering of records in this report file(.rpt).

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;

enter image description here

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

link for pivote

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.


Solution

  • Since you got some output, now to manuplate that output as required use cross tab in crystal report.

    1. Use bn in column.
    2. Create a formula @Count and write just "Count" in that formula and use the formula in rows.
    3. Use database field 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