It depends on how you want to retrive your data. I use SQL stored procedures to declare variables. All I do is create a stored procedure, then insert those fields on the report, using insert fields.Then insert the desired fields.
I am still confused on where do I declare the variable.
Example:
Let's say that I have 2 fields in a report, 1) Last Name 2) First Name. I want to run a formula that evaluates the Last Name and if the last name = "Smith" I want this formula to store the number 1 in a variable. At the end of the report, I want to print this Variable in the report footer.
Questions:
Where do I declare the variable? Do I use a formula field to do so or..??
How do I call the variable so I can give it a new value using a formula?
How do I call the variable to print it in the report?
whileprintingrecords;
numbervar Smiths;
If {table.last} = "SMith" then
Smiths:=Smiths+1
In the report footer you could use th following to display it:
whileprintingrecords;
numbervar Smiths
This is a bad example because there are much simpler ways to accomplish this, such as a Running Total, select the field, use a count as the type, and in the Evaluate Use a Formula just place {table.last} = "Smith"
Or you might use a Cross-Tab and place the Last Name in the Rows and in the summary section and select count to get all names in one simple action (place the cross-tab in the report header or report footer).
Ratehr than suggesting technologies, try posting example data and expected output just in case others might have something meaningful to contribute to the design.
Hi,
Create a formula called IsSmith ( for instance):
If LastName = "Smith" then 1 else 0
place this in the detail section of your report ( you can suppress it so it does not display)..Summarize it as a Grand Total( if you want it in the footer)( Right-click on the formula field, insert Grand Total as Sum)
I did this, and it works, but it does not retain the value. If at the 'if' evaluates to true then it stores the value, but if it evaluates to false in the following record, it resets the value to 0 even knowing that I am not stating an 'else' statement to reset to 0. I had the same problem by using the formula itself without using the variable (that was my first try).
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
numbervar WednesdayCount:= {#DayWorkedTotal};
if DayOfWeek ({table.event.date}) = 4 then
WednesdayCount := {#DayWorkedTotal}//please note that I am not trying to increment the value, just replace it.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
REFRAISING...I did not initialize the variable.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
numbervar WednesdayCount;
if DayOfWeek ({table.event.date}) = 4 then
WednesdayCount := {#DayWorkedTotal}//please note that I am not trying to increment the value, just replace it.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
If you want to display the running total as it is incrementing with the most recent value, then change the formula to:
numbervar WednesdayCount;
if DayOfWeek ({table.event.date}) = 4 then
WednesdayCount := {#DayWorkedTotal} else
WednesdayCount := WednesdayCount;
Otherwise, without making that change, you can create a formula like the following which will display the most recent increment in a group or report footer section, even if the last few records display as zero:
TekAtWork, I suspect you've come to Crystal from Mainframe languages, as I did. It has its own design philosophy, which doesn't really include storing data in work-fields for use elsewhere. You can get the same effect using the methods described above.
Other confusing topics are null and left-outer joins. If you've not already figured them, you'd do well to use Search to look them up.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.