Link to home
Start Free TrialLog in
Avatar of mtrout
mtroutFlag for United States of America

asked on

Use Select with prompt

Hello,
I would like to take a very long IF-THEN-Else statement and make into a case statements if possible.

What I have:
(if uppercase({?Location})='ALL'
then
true
else
if {?Location}='Washington, DC'
then
{Table_A.citystate} in ["Washington Area, DC","Washington, DC","Washington Navy Yard"]
else
if  (tons of more else if's)
else
{?Location}={TABLE_A.citystate})

The report prompts for a location and other prompts, but for this one (location), I was hoping to make case statements for the location.  Can you please assist?  Thank you.
Avatar of Michael Carrillo
Michael Carrillo
Flag of United States of America image

I am not sure I understand your request.

You could create a variable (YourVariable) and set it equal to uppercase({?Location}).
Then use it in your case statement:

select YourVariable
Case 'ALL'
...
Case 'WASHINGTON, DC'
...
Case '....'
...
Avatar of Mike McCracken
Mike McCracken

Close.  Need : after the case 'x' :

select YourVariable
Case 'ALL' :
...
Case 'WASHINGTON, DC' :
...
Case '....' :
...
Default :

mlmcc
Avatar of mtrout

ASKER

this is what I tried and it's not working.  received the message that the remianing text does not appear to be part of the formula.  
 I have other if than statements above, it flaggs all of the statements that are commented out and I checked them all.  Have I messed up the Default statement?  What did I do wrong?  Thank you.  Oh, I just did two out of the many I will need to do.  Thank you.
and
select {?Location}
Case "ALL":
true
Case "Washington, DC":
"Washington Area, DC","Washington, DC","Washington Navy Yard"
Case "Clearwater, FL":
"Clearwater, FL","Clearwater , FL"
Default:
{?Location}= {TABLE_A.citystate}
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am not sure if the Crystal Reports Case statements require a break or not.  If you have problems with the syntax, try a break as follows:

select {?Location}
Case "ALL":
  true
  break
Case "Washington, DC":
  {TABLE_A.citystate}  IN ["Washington Area, DC","Washington, DC","Washington Navy
  break
Case ...
As far as I know it doesn't require the break.

mlmcc
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mtrout

ASKER

Hello There,

 Thank you so much.  I used a combination of two responses:
I like the usage of IN, that's what I was using and I separated the ALL so that if someone used aLL or AlL and it goes on...I will not need to worry.  I prefer using the uppercase function.  Thank you again mlmcc and James.

and
((if uppercase({?Location}) = 'ALL'
then
true)
or
(select {?Location}
Case "Washington, DC":
{TABLE_A.citystate} in ["Washington Area, DC","Washington, DC","Washington Navy Yard"]

case "Clearwater, FL":

{TABLE_A.citystate}  in ["Clearwater, FL","Clearwater , FL"]

case "Pittsburgh, PA":
{{TABLE_A.citystate}  in ["Pittsburgh, PA","Pittsburg, PA","Pittsuburgh, PA"]

Default: {?Location}= {TABLE_A.citystate}))
You're welcome.  Glad I could help.

 James