Print Page | Close Window

Name Formula

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=22514
Printed Date: 03 May 2024 at 2:49am


Topic: Name Formula
Posted By: NCGOV
Subject: Name Formula
Date 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.





Replies:
Posted By: kevlray
Date 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


Posted By: NCGOV
Date 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.





Posted By: kevlray
Date 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.



Print Page | Close Window