Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

about sql

Status
Not open for further replies.

qwertyu1

Technical User
Nov 1, 2006
57
US
Hello all,

I am using crystal xi and oracle 9.

I got a sql like following :

select r.PRIM_TIMBER_TYPE ptt,
tt.TIMBER_TEXT ptx,
count(r.RECON_ID),
sum(r.ACRES_AMT) Acres,

TO_CHAR(sum(r.ACRES_AMT)/TO_NUMBER:)P53_RECON_ACRES,'999999999')*100,'990.99') P,

TO_CHAR(sum(r.ACRES_AMT)/TO_NUMBER:)P53_FORESTED_ACRES,'999999999')*100,'990.99') P2

from fr_recon r, fr_timber_type tt

where r.FR_PROP_CODE = :p0_PROPERTY
and
r.PRIM_TIMBER_TYPE = tt.TIMBER_TYPE
and
tt.FOREST_FLAG = 'F'

group by r.PRIM_TIMBER_TYPE, tt.TIMBER_TEXT




note:
sql for ::p53_RECON_ACRES

(select sum(r.ACRES_AMT)
from fr_recon r
where r.FR_PROP_CODE = :p0_PROPERTY)



sql for::p53_FORESTED_ACRES

(select sum(r.ACRES_AMT)
FROM fr_recon r, fr_timber_type tt
where r.PRIM_TIMBER_TYPE = tt.TIMBER_TYPE
and tt.FOREST_FLAG = 'F'
and r.FR_PROP_CODE = :p0_PROPERTY
and nvl(instr(r.STAND_PREFIX_CODE,'R'),0) = 0
and nvl(instr(r.STAND_PREFIX_CODE,'Y'),0) = 0
and nvl(instr(r.STAND_PREFIX_CODE,'Z'),0) = 0)


sum(r.acres_amt) this is the total amount for all prop_codes.

actually i can able to get the below fields on report.

r.PRIM_TIMBER_TYPE ptt,
tt.TIMBER_TEXT ptx,
count(r.RECON_ID),
sum(r.ACRES_AMT) Acres,

for last 2 fields i confused.
anybody can tell how can i get last 2 fields on report.


 
Click on the fields, let Crystal do the work for you.

There are several ways to find totals: running totals, summary totals and variables. Right-click on a field and choose Insert to get a choice of Running Total or Summary. Or else use the Field Explorer, the icon that is a grid-like box, to add running totals.

Running totals allow you to do clever things with grouping and formulas. They also accumulate for each line, hence the name. The disadvantage is that they are working out at the same time as the Crystal report formats the line. You cannot test for their values until after the details have been printed. You can show them in the group footer but not the group header, where they will be zero if you are resetting them for each group.

Summary totals are cruder, but are based directly on the data. This means that they can be shown in the header. They can also be used to sort groups, or to suppress them. Suppress a group if it has less than three members, say. They default to 'Grand Total', but also can be for a group.

Variables are user-defined fields. One useful variant are shared variables to pass data from a subreport back to the main report. You can also use variables to show page totals. For normal counting I find running totals or summary totals much easier.

Directly Calculated Totals within a Formula Field can be coded directly, with commands like Sum ({ADV01.Advance}, {ADV01.AccType}). The same result can be achieved by picking up an existing Variable, and will keep the code even if the Variable itself is later deleted. Formula fields can also include Running Totals and other Formula Fields, with some limits depending on when the values are calculated.

It is also possible to get totals using a Formula Field, which can contain a Variable or a Directly Calculated Total.

To get yourself familiar with the idea, try doing a test report with a summary total and a running total for the same field, placed on the detail line. You'll find that the running total increases as each line is printed, whereas the summary total has the final value all along.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Madawc,

Since this is a standard mini-faq that you often provide, I wonder whether you would consider editing it so that it does not refer to summary totals as "cruder", since in fact they should always be first choice if they can be used--because they are the most efficient kind of summary and are faster than running totals, which can bog a report down, and should be avoided except when they are the only way to get the correct results.

-LB
 
Point taken, I'll amend it. Should I turn it into an actual FAQ? 'Basics of totalling', and others could add to it.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top