Click to See Complete Forum and Search --> : Proper SQL Operator?


GulfCoast
10-23-2003, 02:56 PM
SELECT *
FROM Saddle
WHERE Brand = '#URL.Brand#' OR Type = '#URL.Type#'
ORDER BY Brand ASC

How would the WHERE be altered to allow searches by "Brand AND Type" as well
as "Brand OR Type"? I want to be able to allow both options.
Thank you!

srr
10-23-2003, 02:56 PM
"GulfCoast" <csadd@charlottes-saddlery.com> wrote:
>
>SELECT *
>FROM Saddle
>WHERE Brand = '#URL.Brand#' OR Type = '#URL.Type#'
>ORDER BY Brand ASC
>
>How would the WHERE be altered to allow searches by "Brand AND Type" as
well
>as "Brand OR Type"? I want to be able to allow both options.
>Thank you!
>
Change the Where Clause to somthing like this
WHERE ((Brand = @Brand OR Brand IS NULL) AND (Type = @Type OR Type IS NULL))

This will help with
Brand X AND Type Null
Brand Null AND Type X
Brand Null AND Type Null

Warning This will also return all records if no data is submitted

Hope this helps

Scott

srr
10-23-2003, 02:56 PM
"srr" <test@aol.com> wrote:
>
>"GulfCoast" <csadd@charlottes-saddlery.com> wrote:
>>
>>SELECT *
>>FROM Saddle
>>WHERE Brand = '#URL.Brand#' OR Type = '#URL.Type#'
>>ORDER BY Brand ASC
>>
>>How would the WHERE be altered to allow searches by "Brand AND Type" as
>well
>>as "Brand OR Type"? I want to be able to allow both options.
>>Thank you!
>>
>Change the Where Clause to somthing like this
>WHERE ((Brand = @Brand OR Brand IS NULL) AND (Type = @Type OR Type IS NULL))
>
>This will help with
>Brand X AND Type Null
>Brand Null AND Type X
>Brand Null AND Type Null
>
>Warning This will also return all records if no data is submitted
>
>Hope this helps
>
>Scott
>
I made a mistake in the where clause
WHERE ((Brand = @Brand OR @Brand IS NULL) AND (Type = @Type OR @Type IS NULL))

That is checking to search for one or the other and for an inclusive between
the two.

Onuar
10-31-2003, 11:56 AM
"srr" <test@aol.com> wrote:
>
>"srr" <test@aol.com> wrote:
>>
>>"GulfCoast" <csadd@charlottes-saddlery.com> wrote:
>>>
>>>SELECT *
>>>FROM Saddle
>>>WHERE Brand = '#URL.Brand#' OR Type = '#URL.Type#'
>>>ORDER BY Brand ASC
>>>
>>>How would the WHERE be altered to allow searches by "Brand AND Type" as
>>well
>>>as "Brand OR Type"? I want to be able to allow both options.
>>>Thank you!
>>>
>>Change the Where Clause to somthing like this
>>WHERE ((Brand = @Brand OR Brand IS NULL) AND (Type = @Type OR Type IS NULL))
>>
>>This will help with
>>Brand X AND Type Null
>>Brand Null AND Type X
>>Brand Null AND Type Null
>>
>>Warning This will also return all records if no data is submitted
>>
>>Hope this helps
>>
>>Scott
>>
>I made a mistake in the where clause
>WHERE ((Brand = @Brand OR @Brand IS NULL) AND (Type = @Type OR @Type IS
NULL))
>
>That is checking to search for one or the other and for an inclusive between
>the two.

check this one

WHERE NOT ((Brand IS NULL) AND (Type IS NULL))