Tutorial :Crystal Reports query help if-then-else


Basically I have a field in my table called sex, and it's a boolean. true for male, false for female. How can I display it this way instead of as 0, 1?


You want to create a formula field and add the formula field to the report instead of the sex field. Something like this should work (my syntax may be slightly off)

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

If you are unfamiliar with formula fields they are just expressions you can use and display in the report. In the 'Field Explorer' side bar in Crystal Reports you can see list of all the Database Fields etc. Just right click on the Formula Fields and add a new one. After you create the formula field you drag it onto your report layout just like any other normal field.


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

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

My Crystal formula syntax is really rusty, so that may not be right as written. It might need to be :

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

And the line-end (";") format might not be right....


If you right-click on the original database field and choose "Format Field...", you can set the Display String on the Common tab using one of the formulas above, instead of creating a separate formula to do the calculation.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »