问题描述
我有一个允许多个值的参数.它用于我数据库中的名称字段.我想要做的是允许用户输入一个名称,然后让水晶找到任何名称,就像他们输入的任何名称一样.因此,例如,您可以输入 4 个姓氏,并且水晶会返回在姓名字段中具有任何这些名字的任何人.我可以让like"正常工作,但前提是数组中有一个字符串.这是我的选择公式:
I have a parameter that allows multiple values. Its for a name field in my database. What I want to be able to do is allow the user to put in a name and then have crystal find any name like any of the names they entered. So for example you could put in 4 last names and crystal would return anyone who had any of those names in the name field. I can get the "like" to work just fine, but only when there is one string in the array. Here is my select formula:
numbervar counter := 1;
numbervar positionCount:=count({?Customer Name}); //I'm not sure what to put
here. Count? UBound?
if {?Customer Name}[1] <> 'ALL'
then
(
while(counter <= positionCount)
do
(
{NAMEFIELD} like '*' & {?Customer Name}[counter] & '*';
counter := counter + 1;
);
)
else
if {?Customer Name}[1] = 'ALL'
then
true
)
此公式返回所有名称,而不是参数中的名称.关于我做错了什么有什么想法吗?
This formula returns all of the names, not the ones in the parameter. Any ideas on what I'm doing wrong?
推荐答案
使用这些属性创建一个多值参数({?Customer Name}):
Create a multi-value parameter ({?Customer Name}) with these properties:
- 默认值:全部
- 所有多个值:TRUE
在参数的选择列表网格中添加一行;提供 'ALL' 和 'ALL'(不带单引号)
Add a row to the parameter's pick-list grid; supply 'ALL' and 'ALL' (without single quotes)
使用此文本创建自定义函数(名为Delimit"):
Create a Custom Function (named 'Delimit') with this text:
// Delimit()
// enclose each value in array in **, returning an array
Function (Stringvar Array params)
Split("*" + Join(params, "*,*") + "*", ",")
修改报告的记录选择公式:
Modify the report's record-selection formula:
If {?Customer Name}<>"ALL" Then
{TABLE.CUSTOMER_NAME} LIKE Delimit({?Customer Name})
Else
True
(可选)创建一个公式以使用此文本显示参数的值:
Optionally, create a formula to display the parameter's values with this text:
//{@Customer Name}
Join( Delimit({?Customer Name}), ";")
这篇关于循环遍历多值参数数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!