Solved

Multi value parameter in SQL command - CR2013

Posted on 2015-02-17
4
211 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 100

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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