0
votes

I am creating a Crystal Report. In my report there are three parameters. Now I would like to filter data according to the parameter value. Therefore in record selection formula I have written the following formula.

(
    {Table_Name.Field01} = {?Field01}
)
and
(
    if HasValue({?Field02}) Then 
        { Table_Name. Field02} Like ('*'+{?Field02}+'*') 
    else true
)
and
(
    if HasValue({?Field03}) Then 
        { Table_Name. Field03} = ToNumber({?Field03}) 
    else True
);

The problem is not working. It’s only working if I add the third parameter in my IF condition.

and
(
    if HasValue({?Field03}) Then 
        { Table_Name. Field03} = ToNumber({?Field03}) 
    else True
);

Can anyone give me idea how to fix the problem. I am using Crystal Report 2008.

1

1 Answers

1
votes

I would suggest avoiding the use of optional parameters- they tend to break things. If instead you can set default values- something like this:

Parameters; Name (default *ALL), Hair (default *ALL)

Then i also tend to avoid using if/then/else in record selection- stick to logical operators (and/or):

({?name} = '*ALL' or {table.name} = {?name})
and ({?hair} = '*ALL' or {table.hair} = {?hair})

In response to your additional question:

ucase({i.fnavn}) like '*' + ucase({?navn}) + '*'
or ucase({i.enavn}) like '*' + ucase({?navn}) + '*'
or ucase({i.navn}) like '*' + ucase({?navn}) + '*'