Solved

Multi value parameter in SQL command - CR2013

Posted on 2015-02-17
4
215 Views
Last Modified: 2015-02-23
Im using CR2013 to query an oracle 11 database.

I want to use a multi value parameter in my sql query (rather than using the parameter in the select expert).
 So far I have:

1. created a parameter in the 'Command Parameter' dialog box called p_student
2. checked the 'Allows multiple values' checkbox in the 'Command Parameter' dialog box
3. added the parameter into the query using syntax:
       where student.studentname in ({?p_student})

4. added the following values into the p_student parameter:
      George
      Paul
      Ringo
      John

This seems to work fine, but now I want to add an additional parameter option called 'All students':

All students
      George
      Paul
      Ringo
      John

Which when selected would pass the following sql into the query:

      Where Student.studentname like ‘%’

So would return all students

The logic would be

Case when
{?p_student} = ‘All Students’ then
where Student.studentname like ‘%’
else
where student.studentname in ({?p_student})
end

Any help with the syntax is appreciated.
0
Comment
Question by:tonMachine100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 40614312
Rather than that just use TRUE

Probably more like

WHERE
   Case When {?p_student} = ‘All Students’ then TRUE
   ELSE  student.studentname in ({?p_student})
   END

mlmcc
0
 
LVL 35

Accepted Solution

by:
James0628 earned 500 total points
ID: 40616247
I think the only real problem with your syntax is that the CASE needs to be in the WHERE clause (as in mlmcc's post), not the other way around.

 IOW, instead of

CASE
(WHERE clause)
END

 you want

WHERE
(CASE
END)

 And mlmcc had a very good point about using TRUE, instead of your LIKE.  There's no point in doing a wildcard comparison, if you don't have to.

 However, while I think the CASE would work, it's probably the wrong way to go here.  The "normal" way to do a test like that would be:

WHERE
({?p_student} = ‘All Students’ OR student.studentname IN ({?p_student}))


 Although, if the parameter allows multiple values, you may need/want to use:

WHERE
(‘All Students’ IN ({?p_student}) OR
student.studentname IN ({?p_student}))

 James
0
 

Author Closing Comment

by:tonMachine100
ID: 40626159
that works- thanks
0
 
LVL 35

Expert Comment

by:James0628
ID: 40626183
You're welcome.

 FWIW, mlmcc probably deserved some of the points, since he responded first, and I think his basic syntax would work.  You could ask to have the question re-opened, and then split the points between us.

 James
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question