将多个列值连接成一个字符串 - 水晶雷波特公式



假设,我在下面有这些记录(有 4 个字段(-

.---------.---------.------.---------.
|  Col1   |  Col2   | Col3 |  Col4   |
:---------+---------+------+---------:
| Value A | Value B | null | Value C |
'---------'---------'------'---------'

现在我必须使用水晶报告中的公式将它们组合成一个字符串,就像这样-

Value A, Value B and Value C

注意:它应该以"和"结尾

转到您的字段资源管理器,右键单击公式,然后单击新公式。

然后,您可以输入公式。您的等式应类似于 {YourDataSource.Col1} & ", " & {YourDataSource.Col2} & " 和 " & {YourDataSource.Col4}。单击保存并关闭,然后将此公式拖到您的报表上即可。

我不确定你的笔记是什么意思,但我希望这会有所帮助。另外,请查看连接两个字段 如果我的回答还不够。

使用 IsNull(( 函数检测哪些列为空并跳过它们。例如:

Local StringVar result;
Local StringVar connector := "";
IF Not IsNull({Col4}) Then
(
result := {Col4};
connector := " and "
);
IF Not IsNull({Col3}) Then
(
result := {col3} & connector & result;
IF connector = "" Then connector := " and "  Else connector := ", " 
);
IF Not IsNull({Col2}) Then
(
result := {col2} & connector & result;
IF connector = "" Then connector := " and "  Else connector := ", " 
);
IF Not IsNull({Col1}) Then
(
result := {col1} & connector & result;
);

最新更新