On Mon, 25 Nov 2013 09:57:03 +0100, Mark Rotteveel <[email protected]>
wrote:
> On 24 Nov 2013 23:46:29 -0800, <[email protected]> wrote:
>> Hi all
>> 
>> I have a query in which I need to use either of two WHERE clauses
>> depending on the parameters passed or no parameter passed to the query
> (via
>> Remote View in VFP)
> ...
>> 
>> Please advise on if and how I can have two different WHERE clause
>> depending on external parameters having values.  Till now I have passed
>> parameters but the WHERE has always been one that adapted to the values
>> passed as parameters.
> 
> I found your where clauses not very readable, so I'll give a general
> recipe:
> 
> SELECT
> ...
> FROM ....
> WHERE <condition for first-set-of-conditions> AND
> (<first-set-of-conditions>)
> OR <condition for second-set-of-conditions> AND
> (<second-set-of-conditions>)
> 
> EG
> 
> SELECT
> *
> FROM mytable
> WHERE ? IS NULL AND (x=y)
> OR ? IS NOT NULL AND (x=? OR y=?)

Small addendum: usually these kind of solutions lead to bad performance,
you might want to consider using two different queries and decide in your
application, or maybe in a stored procedure.

Mark

Reply via email to