0

I have 2 checkboxes on one page and a search button on another page that needs to take into consideration if the checkboxes are checked or not. I need to be able to search 4 different ways:
both checkboxes are checked
neither checkboxes are checked
checkbox1 is checked and checkbox 2 is not checked
checkbox1 is not checked and checkbox 2 is checked

Currently I have a stored procedure that has:

Select chkbox1, chkbox2 (database fields)
    From table
    Where conditions are equal
    If chkbox1 = ‘Y’ and chkbox2 = ‘Y’ then
        Select statement
    Else if chkbox1 = ‘N’ and chkbox2 = ‘N’ then
        Select statement
    Else if chkbox1 = ‘Y’ and chkbox2 = ‘N’ then
        Select statement
    Else if chkbox1 = ‘N’ and chkbox2 = ‘Y’ then
        Select statement
    End if

This is not working in my stored procedure. How can I do this?

Edited by pritaeas: Moved to Databases.

3
Contributors
2
Replies
18
Views
4 Years
Discussion Span
Last Post by 1stDAN
0

That depends on your current database system. For example, MySQL only allows if statement in stored procedure AND there not be part of a select statement, Click Here, However, "else if" must be written "elseif", without space. Within select statements MySQL don't know pure ANSI-standardized if-Statement! There only case-statement is allowed as gusano79 already sayed.

Edited by 1stDAN

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.