Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: Concatenate formula when one field is empty Post Reply Post New Topic
Author Message
aaml216
Newbie
Newbie
Avatar

Joined: 02 Nov 2011
Online Status: Offline
Posts: 24
Quote aaml216 Replybullet Topic: Concatenate formula when one field is empty
    Posted: 10 Jun 2015 at 8:21am
I did a simple formula to combine the name fields into one, e.g. Smith, John A

{DEMOGRAPHICS.LASTNAME} & ", " & {DEMOGRAPHICS.FIRSTNAME}& " "&
{DEMOGRAPHICS.MIDDLEINITIAL}

But it only works if the person has a middle initial. Otherwise it returns a blank field. I want the name returned regardless of whether they have a middle initial.

Thanks!
Amanda from the Mid-Atlantic
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 10 Jun 2015 at 9:24am
likely the NULL in the MI is stopping the formula fom returning anything.
either set the formula to use 'default values for null' or handle it as
 
{DEMOGRAPHICS.LASTNAME} & ", " & {DEMOGRAPHICS.FIRSTNAME}&
(If is null {DEMOGRAPHICS.MIDDLEINITIAL} or trim({DEMOGRAPHICS.MIDDLEINITIAL})="" then "" else 
{DEMOGRAPHICS.MIDDLEINITIAL} )
 
 
IP IP Logged
aaml216
Newbie
Newbie
Avatar

Joined: 02 Nov 2011
Online Status: Offline
Posts: 24
Quote aaml216 Replybullet Posted: 11 Jun 2015 at 3:24am
Thanks so much for taking a look at this. I am getting an error message though. All I did was to change "is null" to "isnull." I think the error it may have to do with the parentheses...? It is saying that after the isnull portion, it is ready to see a "then."

What is the purpose of the trim statement?
Amanda from the Mid-Atlantic
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 11 Jun 2015 at 5:00am


Personally I have good success with the following setup.
{DEMOGRAPHICS.LASTNAME} & ", " & {DEMOGRAPHICS.FIRSTNAME}&(if len({DEMOGRAPHICS.MIDDLEINITIAL}) >0 then " " & {DEMOGRAPHICS.MIDDLEINITIAL} else "")
IP IP Logged
aaml216
Newbie
Newbie
Avatar

Joined: 02 Nov 2011
Online Status: Offline
Posts: 24
Quote aaml216 Replybullet Posted: 11 Jun 2015 at 5:38am
kevlray - Sorry, I still only get patients who have middle initials...
Amanda from the Mid-Atlantic
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 11 Jun 2015 at 8:34am
Sorry, I inserted some SQL ...

(If isnull({DEMOGRAPHICS.MIDDLEINITIAL}) or trim({DEMOGRAPHICS.MIDDLEINITIAL})="" ...

The trim is accounting for any middle initials that someone stuck in a space instead of an empty string.

Kevlray's code will work if you set the formula field to use default values for nulls
IP IP Logged
aaml216
Newbie
Newbie
Avatar

Joined: 02 Nov 2011
Online Status: Offline
Posts: 24
Quote aaml216 Replybullet Posted: 11 Jun 2015 at 8:38am
So the ... is:

then {DEMOGRAPHICS.LASTNAME} & ", " & {DEMOGRAPHICS.FIRSTNAME}& " " & {DEMOGRAPHICS.MIDDLEINITIAL}

Sorry to be so dense. I am pretty new to this.
Amanda from the Mid-Atlantic
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 11 Jun 2015 at 10:43am

{DEMOGRAPHICS.LASTNAME} & ", " & {DEMOGRAPHICS.FIRSTNAME}&
(If isnull({DEMOGRAPHICS.MIDDLEINITIAL}) or trim({DEMOGRAPHICS.MIDDLEINITIAL})="" then "" else
{DEMOGRAPHICS.MIDDLEINITIAL} )

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.016 seconds.