Link to home
Start Free TrialLog in
Avatar of Annette Wilson, MSIS
Annette Wilson, MSISFlag for United States of America

asked on

Crystal Reports - If left 4 equal then print text

Hi,

I see that there is a string function in Crystal Reports that allows me to replace a string is follows:

a:=replace(a,"EAN", "NEW");

I want to say, If the first four character in a string equals "SAMP" then replace with "NEWSAMP".

How do it do this in Crystal Reports?
Avatar of Mike McCracken
Mike McCracken

StringVar a;
If Left({a,4) = "SAMP" then
    a := "NEW" & a;

mlmcc
Avatar of Annette Wilson, MSIS

ASKER

mlmcc,

Thank you for responding.  In your solution, where is the field value evaluated?

If Left 4 of {FIELD} = "SAMP" then string = "NEW"
Is a a variabloe or a field?

If it is a field you can't change field values.

mlmcc
Can I have a function that reads the first 4 characters in the field and when and display text according to the first 4 characters.  

I'm not trying to change field values, just make sure the when a field has a certain first 4 characters that the report displays text.  

I am able to do this in other reporting programs with a StringIF function.

Is there a StringIF in Crystal Reports?
There is no stringIf.

You can use

If Left({YourFIeld},4) = "SAMP" then
    "NEW"
Else if Left({YourFIeld},4) = "STAN" then
    "OLD"
etc

mlmcc
ASKER CERTIFIED SOLUTION
Avatar of Annette Wilson, MSIS
Annette Wilson, MSIS
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try this

If UpperCase(Left({Field},4)) = "RNDT" then
      "RUN CONTROLLED"
Else if UpperCase(Left({Field},3)) = "TAC" then
      "TACT CONTROLLED"
Else
      {Field}

mlmcc
Did you need the formula?

mlmcc
Thank you very much.  This worked.  I traced the data in the database and the data was never populated.  Once I took care of the correct query,  everything worked just fine.