Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Name Formula Post Reply Post New Topic
Author Message
NCGOV
Newbie
Newbie
Avatar

Joined: 04 Oct 2016
Online Status: Offline
Posts: 24
Quote NCGOV Replybullet Topic: Name Formula
    Posted: 29 Dec 2017 at 10:48am
How do I combine these two formulas into one?

Last Name:
local stringvar ln := {unit.name};

if instr (ln, ",") > 0 then
    trim(split(ln, ",")[1])
else trim(ln)


First Name:
local stringvar fn := {unit.name};

if instr (fn, ",") > 0 then
    local stringvar fo := trim(split(fn, ",")[2]);

if instr(fo, " ") > 0 then
    split(fo, " ")[1]
else fo


I want to combine the first and last name formula into one where it will read LAST, FIRST.




Edited by NCGOV - 29 Dec 2017 at 10:52am
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 02 Jan 2018 at 4:01am
So you are saying you want to return the value Last, First?

Combine the two formulas formulas or call both formulas (change local variables to global or shared variables) and have the following line as the last line in the combined formula (slightly different if you call the formulas).

ln + ', '+ fo
IP IP Logged
NCGOV
Newbie
Newbie
Avatar

Joined: 04 Oct 2016
Online Status: Offline
Posts: 24
Quote NCGOV Replybullet Posted: 10 Jan 2018 at 4:12am
So is this what you are suggesting?

global stringvar ln := {unit.name};

if instr (ln, ",") > 0 then
    trim(split(ln, ",")[1])
else trim(ln)


global stringvar fn := {unit.name};

if instr (fn, ",") > 0 then
    local stringvar fo := trim(split(fn, ",")[2]);

if instr(fo, " ") > 0 then
    split(fo, " ")[1]
else fo

ln + ', '+ fo

....that did not work.





Edited by NCGOV - 10 Jan 2018 at 4:14am
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 10 Jan 2018 at 4:49am
Error message?  Not the right result?

FYI:  I would be wary of declaring a variable in the middle of the code. If you if statement is false then fo is not created.  Also make sure you have set 'Default Values for Nulls' in the formula editor.
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.063 seconds.