Solved

Multi value parameter in SQL command - CR2013

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now