连接单个数据库字段的多个值

时间:2011-08-22 23:47:56

标签: crystal-reports concatenation

我有一个报告,它从存储过程中引入值。我想将这些值中的一些用作报告标题的一部分。

我正在尝试找到一种方法从数据库字段“Distrib”中取出每个2到5个不同的值,并在必要时将它们连接起来以制作标题,用空格和逗号分隔。

如果我在C#中这样做,我会使用foreach并打印出每个值,但我在Crystal Reports中看不到这样的功能。

如何连接单个数据库字段中的每个值? FWIW,该字段当前用于填充交叉表中的行。我也想过访问那个跨表字段,但是我不知道在函数中它是如何实现的。

1 个答案:

答案 0 :(得分:4)

创建一个名为'push'的公式,将其添加到Detail部分,禁止它,然后将以下内容添加到其文本中:

//{@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;

创建一个名为'serialize'的公式,将其添加到Report Header部分,然后将以下内容添加到其文本中:

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

//force evaluation to occur during second pass
WhilePrintingRecords;  

//declare array
Stringvar Array items;

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

此解决方案依赖于我构建的两个自定义函数:Array_Push()Array_Contains()