开发者

Concatenate a single database field's multiple values

开发者 https://www.devze.com 2023-03-30 14:01 出处:网络
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 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,开发者_JS百科 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()

0

精彩评论

暂无评论...
验证码 换一张
取 消