Author |
Message |
drommo
Newbie
Joined: 07 Jun 2011
Location: Guatamala
Online Status: Offline
Posts: 4
|
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 Logged |
|
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
|
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 Logged |
|
drommo
Newbie
Joined: 07 Jun 2011
Location: Guatamala
Online Status: Offline
Posts: 4
|
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 Logged |
|
drommo
Newbie
Joined: 07 Jun 2011
Location: Guatamala
Online Status: Offline
Posts: 4
|
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 Logged |
|
drommo
Newbie
Joined: 07 Jun 2011
Location: Guatamala
Online Status: Offline
Posts: 4
|
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 Logged |
|
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
|
Posted: 08 Jun 2011 at 4:05am |
glad you got a solution.
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 Logged |
|
|