Avatar of mtrout
mtrout
Flag 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.
Crystal Reports

Avatar of undefined
Last Comment
James0628

8/22/2022 - Mon
Michael Carrillo

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 '....'
...
Mike McCracken

Close.  Need : after the case 'x' :

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

mlmcc
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}
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
Mike McCracken

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Michael Carrillo

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 ...
Mike McCracken

As far as I know it doesn't require the break.

mlmcc
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
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}))
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
James0628

You're welcome.  Glad I could help.

 James