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

Crystal Reports Fomula Needed 1

Status
Not open for further replies.

ronbowen

Programmer
Jan 10, 2004
7
US
Hello,

Needing help to solve this issue in Crystal Reports 9 and MS SQL Server.

Example: I have several tables linked on the report two of which are Authors and Codes. Authors has author_id and Codes had code_id with author_id as FK.
For each author_id I obtain multiple Code(code_id) records.

I have grouped on author_id showing code_id, code_desc in the detail. I would like to combine the detail values from multiple records in a single field which I could then place on the group line.

Instead of this:

Last First Code_desc
------- --------- ---------
Lesand Danny ...................Group
1 ...................Detail
2
3
Benedi Eric
7
14

Would like the result to look like this:

Last First Codes
------- --------- -----
Lesand Danny 1,2,3
Benedi Eric 7,14

I don't know if this is possible in Crystal but I think it should be. Any help would be greatly appreciated. Thanks in advance.

Ron
 
You can do this with the following method which displays the group fields in the group footer (with group header and details suppressed):

{@resetcodes} to be placed in the group header:
whileprintingrecords;
stringvar codes := "";

{@codesaccum} to be placed in the details section:
whileprintingrecords;
stringvar codes;

codes := codes + totext({table.code},0,"") + ", ";

{@displaycodes} to be placed in the group footer:
whileprintingrecords;
stringvar codes;

if len(codes) > 2 then
left(codes,len(codes)-2);

If the codes field is already a string, you can eliminate the "totext() function.

Just drag the author name fields into the group footer and suppress the details section and the group header.

-LB
 
Your prompt response was much appreciated. Everything seems to be working until I get to the group footer section.
The issue seems to be with left(codes),len(codes)-2);

If I use the -2 then the last number in the result is trimmed(as shown below 1201799 which should be 12017991). Is this because of the field length.

Further detail:
The codes field is varchar with a length of 15.

Here's what happens:
If only one record it displays fine in the group footer but trimmed.
1201799
The detail when not suppressed shows me the following:
1201799112017991,

If 4 records were to be in the detail section then nothing displays in the group footer for that author.
The detail section shows me:
1201763512017635,
1201798212017982,
1201830612017306,
k5440ttk5440tt,
while the group footer section remains blank.

I'm really excited about getting this solution resolved.
Sorry if I didn't provide enouth information the first time around.
Thanks again.
Ron
 
it should be

left(codes,len(codes)-2);

not left(codes),len(codes)-2);


You say this is Varchar(15)??? I count 16 characters in 1201763512017635

Did you make the field wide enough to display such large numbers?? Also you should enable the "can Grow" for the formula field displaying the codes in the footer.

Jim Broadbent

The quality of the answer is directly proportional to the quality of the problem statement!
 
Jim,

Yes on both of your questions.

The error was in my typing of the @codesaccum formula. I've
corrected it and I'm getting the desired result.

Thank you lbass for the solution and Jim for your reply.

Ron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top