Print Page | Close Window

Merge records into continuous string

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=18394
Printed Date: 05 May 2024 at 12:10pm


Topic: Merge records into continuous string
Posted By: JennyB
Subject: Merge records into continuous string
Date Posted: 08 Jan 2013 at 2:09am
Hi,

I have a report which pulls scoreboard messages. These are all held in separate records in a table. For my report output I want to merge these into one single continuous line of text (with a couple of spaces between), so from the original data which is like this:

Message
Message1
Message2
Message3
...

I want to convert it to report output like this:

Message1  Message2  Message3 ...

Any ideas? :) I'd be delighted if its something really obvious and its just me..

Thanks!



Replies:
Posted By: JennyB
Date Posted: 08 Jan 2013 at 3:28am
:) A bit more scouting and I found the answer from here, its ingenious and it concatenates all my records onto one line in my report footer exactly as I wanted them, hooray!:

http://forums.codeguru.com/showthread.php?524357-RESOLVED-Multiple-Rows-to-a-single-row - http://forums.codeguru.com/showthread.php?524357-RESOLVED-Multiple-Rows-to-a-single-row

Study the next solution, where we are concatenating a field and display the resulting string at group or report footer in only one line

To do that, you have to create 3 formulas:

The first one, let's call it @null:
Code:
whileprintingrecords;
stringvar names := "";
Place it in your GH section, it will return you null.



The second one, let's say @comma_field:
Code:
whileprintingrecords;
stringvar names;
names := names & ", " & {table.field};
Place it in your Detail section which you can suppress; the formula will return you next:
, Jules, Christina, Paul


and the 3rd formula, let's call it @final (or whatever you like):
Code:
whileprintingrecords;
stringvar names;
Mid(names, 3);
Place it in your GF or report footer section.



Print Page | Close Window