当前位置: 动力学知识库 > 问答 > 编程问答 >

crystal reports - Concatenate a single database field's multiple values

问题描述:

I have a report that brings in values from a stored procedure. I want to use some of those values as part of the report's Header title.

I'm trying to find a way to take each of the 2 to 5 distinct values from the Database Field "Distrib" and concatenate them to make the title, separated by spaces and commas, when necessary.

If I were to do this in C#, I would use a foreach and print out each value, but I see no such functionality in Crystal Reports.

How may I concatenate each value in an individual database field? FWIW, that field is currently used to populate a row in a cross-table. I thought to access that cross-table field, as well, but I don't see how it's possible from within a function.

网友答案:

Create a formula, named 'push', add it to the Detail section, suppress it, then add the following to its text:

//{@push}
//build an array of unique string values

//force formula to execute during first pass (before grouping and totaling is done)
WhileReadingRecords;  

//create a string array
Stringvar Array items;

//change {table.field} to an appropriate value
items := Array_Push(items, {table.field});

//can't return an array, so use a dummy value
true;

Create a formula named 'serialize', add it to the Report Header section, then add the following to its text:

//{@serialize}
//create comma-delimited list

//force evaluation to occur during second pass
WhilePrintingRecords;  

//declare array
Stringvar Array items;

//serialize array
Join(items, ",");

This solution relies on two custom functions that I built: Array_Push() and Array_Contains()

分享给朋友:
您可能感兴趣的文章:
随机阅读: