CoSpringsGuy
CoSpringsGuy

Reputation: 1645

Using parameters in a Where clause

I have not found an existing thread for exactly what I need. I have a reporting tool that allows me to ask user for input (Client) and pass to SQL as a parameter.

There could be multiple Clients or the word All. If parameter contains 'All' I need to select all records. If the parameter does not contain 'All' I only need to select the records in the parameter.

I found a few solutions that work if the parameter is only one value but mine is a list and needs to use the 'in' predicate. (I think)

Any thoughts?

Upvotes: 1

Views: 3639

Answers (2)

DAiMor
DAiMor

Reputation: 3205

When you speak about Caché, it means that you even have multiple ways how you execute your query. And also there are some ways how to achieve it. I would suggest to use different queries, for ALL records and for chosen. And you can use IN or %INLIST predicate.

Upvotes: 2

Menno
Menno

Reputation: 12641

Without knowing your datamodel, something like the following should do:

SELECT *
FROM clients
WHERE ID IN (@clients) OR 'All' IN @clients

Upvotes: 2

Related Questions