Crystal Reports if-then-else help query

Basically I have a field in my table called sex and it is boolean. true for men, false for women. How can I display it this way and not as 0, 1?

+1


a source to share


3 answers


You want to create a formula field and add a formula field to your report instead of a gender field. Something like this should work (my syntax might be off a bit)

if {MyTable.sex} = 1 
then 
  "male" 
else 
  "female"

      



If you are not familiar with formula fields, they are simply expressions that you can use and display in a report. In the Field Explorer sidebar in Crystal Reports, you can see a list of all fields in the database, and so on. Just right click on the formula fields and add a new one. After you create a formula field, drag it into the report layout just like you would any other normal field.

+4


a source


Use a formula field. Put say @Sex in your report, then edit it to be something like:

//may need tweaked....
If {database.table.sex} then
    male
else
    female;

      

The syntax of my Crystal Formula is really rusty, so it might not be right as written. Maybe it should be:



//may need tweaked....
Stringvar displaySex;
If {database.table.sex} then
    displaySex = "male"
else
    displaySex = "female";
displaySex

      

And the end-of-line format (";") may not be correct ....

+1


a source


If you right-click on a field in the source database and select Format Field ..., you can set the display string in the General tab using one of the formulas above, instead of creating a separate formula to calculate.

0


a source







All Articles