Print Page | Close Window

IF statement not working with String value, help

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=13430
Printed Date: 05 May 2024 at 12:25am


Topic: IF statement not working with String value, help
Posted By: drommo
Subject: IF statement not working with String value, help
Date Posted: 07 Jun 2011 at 11:38am
Hello, I´m trying to concatenate 4 values based on a 5th value result.

This is an extraction of the database I´m using:

Certificado
primer_nombre
segundo_nombre
primer_apellido
segundo_apellido
apellido_casada

I'm using the following formula, but the field won't display any result, nor error messages:

if ({Certificado.apellido_casada}='')
then
{Certificado.primer_nombre}+" "+{Certificado.segundo_nombre}+" "+{Certificado.primer_apellido}+" "+{Certificado.segundo_apellido}
else
{Certificado.primer_nombre}+" "+{Certificado.segundo_nombre}+" "+{Certificado.primer_apellido}+" "+{Certificado.segundo_apellido}+" de "+{Certificado.apellido_casada}

I tried also

if (isnull({Certificado.apellido_casada}=''))

, but this won't work also.

In resume, I would like to show something based on apellido_casada value.

What could be wrong?, Could anybody help me to get the right code to achiev my objective?, thanks for the help.


-------------
186 chars left



Replies:
Posted By: DBlank
Date Posted: 07 Jun 2011 at 11:43am
if any value can be NULL then it will break the result unless you account for this.
I think you can also simply this a bit like this:
 
{Certificado.primer_nombre}+" "+{Certificado.segundo_nombre}+" "+{Certificado.primer_apellido}+" "+{Certificado.segundo_apellido}+
(if " de "+{Certificado.apellido_casada}="" then "" else  " de "+{Certificado.apellido_casada} )


Posted By: drommo
Date Posted: 07 Jun 2011 at 12:01pm
Hello DBlank, thanks for the quick response. I tried your formula, and it will work just when apellido_casada has a value, in other case, it will return blank, I'm trying to figure out how to solve this, I would appreciate if you could guide me to fix this, thank you.

-------------
186 chars left


Posted By: drommo
Date Posted: 07 Jun 2011 at 2:03pm
Hello again DBlank, after making some other investigations in several forums, I found out that you were telling me the answer but I was writting my formula the wrong way.

Since segundo_nombre and segundo_apellido are optional fields, the IF statement should be included too, to avoid break as you said before. The solution to this problem is the following formula:


{Certificado.primer_nombre}+" "+
(if isnull({Certificado.segundo_nombre}) or trim({Certificado.segundo_nombre})="" then "" else {Certificado.segundo_nombre})
+" "+{Certificado.primer_apellido}+" "+
(if isnull({Certificado.segundo_apellido}) or trim({Certificado.segundo_apellido})="" then "" else {Certificado.segundo_apellido})
+(if isnull({Certificado.apellido_casada}) or trim({Certificado.apellido_casada})="" then "" else " de "+{Certificado.apellido_casada})


Thanks for taking the time to help me solve my problem out, have a nice day.

-------------
186 chars left


Posted By: drommo
Date Posted: 07 Jun 2011 at 2:06pm
By the way, I added the or trim({Certificado.segundo_nombre})="" statement, to avoid Blank field problems. Thanks again.

-------------
186 chars left


Posted By: DBlank
Date Posted: 08 Jun 2011 at 4:05am
glad you got a solution. Thumbs%20Up
 
as an FYI, depending on your version there are also ways to make a formula use default values for NULLs so you do not have to write out each possible scenario for NULL or "".



Print Page | Close Window