cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal report: How to concatenate the string whilereadingrecords?

Former Member
0 Kudos

I have description field in the database and I need to concatenate the value of the filed into one line. How to do that? I tried as below

Stringvar strtitle="";

whilereadingrecords;

if Mid({OrderDtl.PartNum},1,2)="T3" Then

strtitle & "T3- Background Music,"

Else if Mid({OrderDtl.PartNum},1,2)="T6" then

strtitle & "T6- Dance"

This is not working and showing only last value instead of concatenated string. I am very new to Crystal report and i am using Crystal report 2008

Thanks,

Raj

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

Try this

In one formula you'd have this -

Global Stringvar strtitle="";

whilereadingrecords;

if Mid({OrderDtl.PartNum},1,2)="T3" Then

strtitle & "T3- Background Music,"

Else if Mid({OrderDtl.PartNum},1,2)="T6" then

strtitle & "T6- Dance"

Place this formula in the detail section and surpress it

Create another formula and have this

WhileReadingRecords;

Global StringVar StrTitle;

Former Member
0 Kudos

Thanks for the reply.

I need this formula to put in the Report footer and cannot put it in the detail section. Even If I use this in the details section and set the suppress for duplicates, it prints one by one; NOT in one single line. I need all the values concatenated into one single line.

abhilash_kumar
Active Contributor
0 Kudos

Hi Raj,

I guess you're trying to concatenate the descriptions so that they appear on a single line, perhaps, on the report footer?

Try this formula:

whilereadingrecords;
stringvar strtitle;
strtitle := strtitle + ">" + {description_field_from_database}

The ">" sign is to separate the records from each other; you may choose to remove this from the formula or use another separator.

Place the above formula in the details section and suppress the section.

Create this formula to display the result and place it in the Report Footer section:

evaluateafter(@Name_of_the_above_formula);
stringvar strtitle;

Let me know how this goes!

-Abhilash

Former Member
0 Kudos

Thanks a lot Abhlash; Problem solved

You are great !!

Former Member
0 Kudos

Hi Abhilash.

I need to break the Loop at one point (Breaking the whilereadingrecords) when it reaches a condition. Is ther any way that I can break the loop in the middle depends on the condition?

abhilash_kumar
Active Contributor
0 Kudos

Hi Raj,

Yes you can add conditions to the formulae as well. When do you want the formula to not execute?

-Abhilash

Former Member
0 Kudos

My requirement is becomding weid now...

'T3', 'T6' are Tariff names to apply for the customer. If I see one of each (T3 and T5) or both, then I should stop running the loop

Like below

"T3- Background Music, T6- Dance' though there are more than 100 lines.

However, now it is printing like below

"T3- Background Music, T6- Dance> T3- Background Music, T6- Dance> T3- Background Music, T6- Dance'' because there are 6 records in the table (3 sets of T3 and T6 tariffs)

Am I confusing ?

Answers (1)

Answers (1)

abhilash_kumar
Active Contributor
0 Kudos

Hi Raj,

The value assignment is done in this way: stringvar strtitle := "";. You're missing the colon sign (:).

In the formula you've assigned/you're trying to assign strtitle a blank value. Since strtitle is blank, this code:

if Mid({OrderDtl.PartNum},1,2)="T3" Then
 strtitle & "T3- Background Music,"
 Else if Mid({OrderDtl.PartNum},1,2)="T6" then
 strtitle & "T6- Dance" 

will always return either T3- Background Music, or T6- Dance.

If you're trying to prefix a string before "T3- Background Music," then you would need to assign something to the strtitle variable.

Hope this helps!

-Abhilash

Former Member
0 Kudos

Hi Abhilash,

I am trying to sort me report based on several field formulas. I have several formulas because I want a blank to appear if value is "" but a word to appear if value is "1". For example, one of my formulas is:  if {Daily_Flash_Report_for_Crystal.Peak?}="1" then "Peak" else "". I need each formula where the words are the same to be grouped together. For example my rpoet layout is:

Group 1: Sales Rep Location

Group 2: Sales Rep

            Account name     Target/Peak/Focus

I want to be able to see all of my "Peak" accounts at the top of the page group, the focus, then target, then blanks.

I am failing at using a parameter. Do you have any suggestions?