Case Statement in Where Clause

  • I have a table with column A. Column A has values 1 or 0. The values represent 2 different outcomes. 1 is cats and 0 is dogs. I want to be able to use the column in a where clause as part of a stored procedure. The parameters are @cats and @dogs. The user can select either @cats or @dogs, or they can select both. If the don't make a selection I want to return both.

    If (@cats is 1 and @dogs is 0) then 'all cats'

    if (@cats is 0 and @dogs is 1) then 'all dogs'

    else 'all cats and all dogs'

  • This seems like a simplified catch-all queries

    http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply