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?

Member Avatar

1stDAN

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.