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!

Pulling values into one text box from three records 2

Status
Not open for further replies.

Azzuri

Programmer
Apr 16, 2002
18
CA
Hello,

I am pulling shift codes for employees and I need to get all the information on one line. Each employee can have one to a maximum of three shift codes per day. I need to get the employees info and all their shift codes for each day on one line. I have the following:

P01111 L9
P01111 M8
P01111 T6

I need it to look like the following:

P01111 L9, M8, T6

Any help would be greatly appreciated. Thanks.
 
One option is to create a string variable, reset it in the Group Header (by employee), add to it the shift code in a detail section formula, and finally display the result in the Group footer (suppressing the display of the detail sections).

Cheers,
- Ido

CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
Like this..., using three formulas:

First formula {@codereset} to be placed in group header, and let's assume you are grouping on {table.emplID}:

whileprintingrecords;
stringvar code := "";
numbervar counter := 0;

{@codeaccum} to be placed in the detail section;

whileprintingrecords;
stringvar code;
numbervar counter;

counter := count([{table.shiftcode}]);

while counter > 0 do
(code:= code + {table.shiftcode}[counter] + ',';
counter := counter - 1);
code [1 to (length(code)-1)];

Third formula {@displaycode}:

whileprintingrecords;
stringvar code;
code;

-LB
 
LB,

Can you explain why you need the counter?

Here's how I would do this (modifying LB's code):
---------------------------------------------------
First formula {@codereset} to be placed in group header,

whileprintingrecords;
stringvar code := "";
---------------------------------------------------
Second formula {@codeaccum} to be placed in the detail section

whileprintingrecords;
stringvar code;
code:= code + {table.shiftcode} + ", ";
---------------------------------------------------

Third formula {@displaycode} to be placed in Group footer:

whileprintingrecords;
code := LEFT(code, Lenght(code)-2);
---------------------------------------------------

Cheers,
- Ido





CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
Ido,

You are absolutely right--the counter is unnecessary. I adapted this from another formula (that I had adapted earlier from some other thread a while back) without thinking about it enough--plus even though I'm daring to answer questions re: variables, they are really new to me. Honestly, I thought the counter had a role in removing the final comma, but it clearly doesn't.

I liked your addition of a space after the comma, and would change the display code to:

whileprinting records;
code [1 to (length(code)-2)];

When I tried your suggested display code:

whileprinting records;
code := left(code, Length(code)-2);

...I couldn't get it to display like this: Ab, Ab, Ab, Ab

I either got AbAbAbAb using -1 instead of -2 or Ab, Ab, Ab, Ab, if I used -2.

-LB

 
You guys are awesome. I pieced together both your codes and it works perfectly. Thanks for all your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top