Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: IF statement not working with String value, help Post Reply Post New Topic
Author Message
drommo
Newbie
Newbie
Avatar

Joined: 07 Jun 2011
Location: Guatamala
Online Status: Offline
Posts: 4
Quote drommo Replybullet Topic: IF statement not working with String value, help
    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
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet 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} )
IP IP Logged
drommo
Newbie
Newbie
Avatar

Joined: 07 Jun 2011
Location: Guatamala
Online Status: Offline
Posts: 4
Quote drommo Replybullet 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
IP IP Logged
drommo
Newbie
Newbie
Avatar

Joined: 07 Jun 2011
Location: Guatamala
Online Status: Offline
Posts: 4
Quote drommo Replybullet 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
IP IP Logged
drommo
Newbie
Newbie
Avatar

Joined: 07 Jun 2011
Location: Guatamala
Online Status: Offline
Posts: 4
Quote drommo Replybullet 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
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet 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 "".
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.