Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Parameter Formula Post Reply Post New Topic
Author Message
lw00
Newbie
Newbie
Avatar

Joined: 25 Sep 2008
Online Status: Offline
Posts: 14
Quote lw00 Replybullet Topic: Parameter Formula
     Posted: 02 May 2009 at 7:31am
I thought this was a simple problem [and it probably is] but I can't seem to figure it out. Here's the situation. I have a view in my database that lists some locations. I let the user select from this list of locations. But I want to get data that can either be in this list, or slightly different.

For instance, let's say my list has 3 entries: 'first', 'second', and 'third'. And the user selects 'first'. I want Crystal Reports to return all records that have their {table.location} == 'first' or 'firstXX'.

I tried doing that in this way having the selection formula like so: {table.location} = {?selectedLocation} or {table.location} = {@locationFormula}. Where location Formula was '{?selectedLocation} & "XX"'. CR complained about {?selectedLocation} having to be an array. I guess because you can select more then one location.

Is there a (simple) way to do this?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 02 May 2009 at 9:39am
Try:
{table.location} LIKE ({?selectedLocation} +"*")
IP IP Logged
lw00
Newbie
Newbie
Avatar

Joined: 25 Sep 2008
Online Status: Offline
Posts: 14
Quote lw00 Replybullet Posted: 02 May 2009 at 10:34am
For some reason when I do this, it gives me all the locations now. So if I select 'first', it will show me 'first', 'second' and 'third' on the report.

Any ideas?

EDIT: I tried using {table.location} = ({?selectedLocation} + "*"). But now if I select 'first', 'second' and 'third' and the database contains 'firstXX', 'second' and 'third'. CR will only display 'second' and 'third'. I think I'm getting closer?

I'm not sure if this behaviour is normal or not but if it is, can someone explain it to me?

Edited by lw00 - 02 May 2009 at 10:43am
IP IP Logged
lw00
Newbie
Newbie
Avatar

Joined: 25 Sep 2008
Online Status: Offline
Posts: 14
Quote lw00 Replybullet Posted: 02 May 2009 at 12:06pm
Alright, I've been working for a while now. This is what I have. For my selection formula I tried to be simple and did this:

if ({table.location} like ({?selectedLocation}[1] + "*")) then
    true
else if ({table.location} like ({?selectedLocation[2] + "*")) then
    true
else
    false


Which works ok and displays the first 2 records I selected within 2 seconds. But when I tried to make it a little more complicated and added a for loop around it like this:

NumberVar ArrayIndex;

For ArrayIndex:=1 to 1 Do
(
if ({table.location} like ({?selectedLocation}[1] + "*")) then
    true
else if ({table.location} like ({?selectedLocation[2] + "*")) then
    true
else
    false
);


CR takes a while (30 seconds or so) then complains to me that it ran out of memory. 'Failed to retrieve data from the database. Out of memory while reading tuples;' which is weird [to me at least] since the previous query only took 2 seconds and the one with the for loop only goes 1 to 1.

Any ideas?

Edited by lw00 - 02 May 2009 at 12:07pm
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 04 May 2009 at 11:47am

I was not looking at your multiple selection critieria.

An Easy solution, assuming you do not have to many options is to make a formula field that is equivalent to your pick list options.
use an instr, or a left to get your formula, example called "NameConvert":
if left({table.location},5)="First" then "First" else
if left({table.location},6)="Second" then "Second" else
if left({table.location},5)="Third" then "Third" else "Not Converted"
 
For your selection criteris you can just point the paramter to = the formula
{@NameConvert} = {?My Parameter}
IP IP Logged
lw00
Newbie
Newbie
Avatar

Joined: 25 Sep 2008
Online Status: Offline
Posts: 14
Quote lw00 Replybullet Posted: 05 May 2009 at 8:20am
Unfortunately I have around 120 choices.  But fortunately I solved my problem in a different, more simple way.  

Thanks DBlank though for your help.  It was greatly appreciated. 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 05 May 2009 at 8:46am
Can you post your solution for others to see?
Thanks
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum