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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Splitting Data in a field to return multiple rows

Status
Not open for further replies.

erniefor

Technical User
Mar 16, 2004
2
US
I have a database that stores multiple codes in on field by separating the results with upper cases.
Example: FeverUnuwekFowdodOther

I want to separate this so it returns a row for each item.

Example:
Fever
Unuwek
Fowdod
Other

Can anyone help?

Thanks
 
I think this might work for you. The result is each 'item' separated by a carriage return, so when you drop this formula onto the report, make sure it's formatted as 'Can Grow':

StringVar str := {Table.YourStringField};
NumberVar i;
StringVar strTemp;
For i := 1 to len(str) do(
if strcmp(UCase(str), str) = 0 then
strTemp := strTemp + " " + str
else
strTemp := strTemp + str);
Join(Split(ltrim(strTemp), " "), chr(13));

The logic here is to loop through the string one character at a time, and add it to a temporary string. If the current character is upper case, a space is added before adding the character to the temp string. Once the looping is through, using a combination of the Split and Join functions, you end up with the desired (I think) result.

If you've got CR 8.5, you might get into trouble with the 255 character string limit if there are too many 'items' in your list.

-dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top