Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I use the IF…ELSE condition in a WHERE clause?

Erhan_torontoNov 15 2013 — edited Nov 17 2013

I want to merge the condition results of my 2 If statements. First if statement result shows only both 0 result, in second if statement result one of them has to be bigger than 0... 

     If (Inventory) <> 0 Then

        If Apple = "" And Banana = "" Then

     strSQL = strSQL & " AND (myApple = 0 AND myBanana = 0)"

  End If

  End If

     If int(Inventory) <> -1 Then

  If Apple = "" And Banana = "" Then

     strSQL = strSQL & " AND (myApple <> 0 OR myBanana <> 0)"

  End If

  End If

**Want to get something like this**

     If int(Inventory) <> 0 Then

            If Apple = "" And Banana = "" Then

       strSQL = strSQL & " AND ((myApple = 0 AND myBanana = 0) AND (myApple <> 0 AND myBanana <> 0))"

    End If

    End If

    If int(Inventory) <> -1 Then

    If Apple = "" And Banana = "" Then

       strSQL = strSQL & " AND (myApple <> 0 AND myBanana <> 0)"

    End If

    End If

   myApple myBanana

         0       0

         0       0

         0       5

         1       0

         6       0

         0       0

      continue.....

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 15 2013
Added on Nov 15 2013
7 comments
8,674 views