Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Strange Concatenation issue Post Reply Post New Topic
Author Message
TorLang
Groupie
Groupie


Joined: 13 Jun 2012
Location: United States
Online Status: Offline
Posts: 50
Quote TorLang Replybullet Topic: Strange Concatenation issue
     Posted: 05 Sep 2013 at 1:05am
Have a strange issue with concatenating a persons name with
last, first middle

Here is my formula for the concatenation:

{TSM040_PERSON_HDR_patient.lst_nm} + ", " + {TSM040_PERSON_HDR_patient.fst_nm} + " " + {TSM040_PERSON_HDR_patient.mid_nm}

What happens is that every so often the entire name is blank in the report. However, if I remove the middle initial part of the concatenation, the name shows up. Any ideas why this might be happening? What if the person does not have a middle initial in the database? Well, other names show up, even if they don't have a middle initial.

Using a text box, and dumping all 3 fields into the text box as:

{TSM040_PERSON_HDR_patient.lst_nm},space{TSM040_PERSON_HDR_patient.fst_nm}space{TSM040_PERSON_HDR_patient.mid_nm}

it comes out fine.
IP IP Logged
TorLang
Groupie
Groupie


Joined: 13 Jun 2012
Location: United States
Online Status: Offline
Posts: 50
Quote TorLang Replybullet Posted: 05 Sep 2013 at 3:30am
If I do this:

if isnull ({TSM040_PERSON_HDR_patient.mid_nm}) then
{TSM040_PERSON_HDR_patient.lst_nm} & ", " & {TSM040_PERSON_HDR_patient.fst_nm} else
{TSM040_PERSON_HDR_patient.lst_nm} & ", " & {TSM040_PERSON_HDR_patient.fst_nm} & " " & {TSM040_PERSON_HDR_patient.mid_nm}

it comes out right. But why would the concatenation care if there is no middle name? And only sometimes? Blows my mind :-)
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 05 Sep 2013 at 4:54am
If you have NULLs and you do not account for them they will stop your formula, any formula, from evaluating when it hits the null value.
Simple way around this to either set your report to use default values for nulls or to use that option in each formula.
You also have to account for the NULLs first in any if-then statement. again, logically, if it hits a null and you do not tell it how to handle it it just stops evaluating. if you tell it how to handle the null then it wil move to the next condition.
IP IP Logged
TorLang
Groupie
Groupie


Joined: 13 Jun 2012
Location: United States
Online Status: Offline
Posts: 50
Quote TorLang Replybullet Posted: 05 Sep 2013 at 5:24am
I had the parameter set in options - reporting. Checking the option in report option however is what made a difference.

Thanks bunches.
IP IP Logged
iSing
Newbie
Newbie


Joined: 12 Mar 2013
Online Status: Offline
Posts: 22
Quote iSing Replybullet Posted: 10 Sep 2013 at 3:40pm
Hi TorLang
 
DBlank is completely right it's all about nulls & how your database handles them & even back to how the data gets there.
 
Imagine this scenario:
User entering client name uses mouse to move from first name field to surname field - thus the middle initial will be null as the user never "activated" this field.   
User entering client name uses tab to go from first name to middle initial to surname - since the middle initial field has been activated, it is no longer null, but will be empty.  The same thing would happen, if they clicked into the middle inital field, but didn't enter anything.  The database then sees that field as existing.
 
That's why your first formula worked for names even if they didn't have a middle intial - as the field wasn't null.
 
You can allow for this scenario (eg middle initial field exists, but contains no data).
 
if (isnull ({TSM040_PERSON_HDR_patient.mid_nm}) or totext({TSM040_PERSON_HDR_patient.mid_nm})="")
then
{TSM040_PERSON_HDR_patient.lst_nm} & ", " & {TSM040_PERSON_HDR_patient.fst_nm} else
{TSM040_PERSON_HDR_patient.lst_nm} & ", " & {TSM040_PERSON_HDR_patient.fst_nm} & " " & {TSM040_PERSON_HDR_patient.mid_nm}

 
IP IP Logged
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