Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to format a field from SQL to Crystal.

Status
Not open for further replies.

32ndFlava

MIS
Mar 2, 2010
4
US
I am building a report and need some help with formating the name field. In the SQL database I am using the name field shows the "Last, Middle First" all in the same field under a title of "Name". I need to create some sort of formula to put the input of "Last, Middle First" onto the report as "First Middle Last" (NOTE: The input has a comma in it, in the database, the output to Crystal should not have a comma) There is no broken up fields in the database such as "First Name", "Middle Name", "Last Name". It is all compressed which is why I am having a problem. Any help would be greatly appreciated!
 
If there are always the three elements to the name, then the following should work:

//{@Firstname}:
stringvar array x := split(x," ");
if ubound(x) = 3 then
stringvar fname := x[3];

//{@Midname}:
stringvar array x := split(x," ");
if ubound(x) >= 2 then
stringvar mname := x[2];

//{@LastName}:
stringvar array x := split(x," ");
if ubound(x) >= 1 then
stringvar lname := left(x[1],len(x[1])-1);

-LB
 
OK, Say the Field I want to pull in from SQL is named "FullName" how would I incorporate that into the formula? Would the "FullName" go in place of the 'x' in the following formula you created?

//{@Firstname}:
stringvar array x := split(x," ");
if ubound(x) = 3 then
stringvar fname := x[3];

Also, Would these essentially be split into three formulas say, "FirstName", "MiddleName","LastName"? Thanks for all your help!
 
It also says that "This array must be subscripted. For example: Array ." refering to the 'x' in the split(x," ") statement.
 
So sorry--silly mistakes. In each formula add the field name in place of the x in the first line, like this:

stringvar array x := split({tablename.fullname}," ");

Replace "tablename" with your actual table name.

-LB
 
Fantastic this worked very well! Thank You so much for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top