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
Solved

Multi value parameter in SQL command - CR2013

Posted on 2015-02-17
4
209 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
  • 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 34

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 34

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 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