-3

我想合并我的 2 个 If 语句的条件结果。第一个 if 语句结果只显示两个 0 结果,在第二个 if 语句结果中,其中一个必须大于 0 ...我想要做的是保留第二个条件不变并首先修改 if statament 像我的代码...

我的代码

If (Inventory) <> 0 Then 
    If Apple = "" And Banana = "" Then
        strSQL = strSQL & " AND (myApple = 0 AND myBanana = 0) + (myApple <> 0 OR myBanana <> 0)"
    End If
End If

//第一的

If (Inventory) <> 0 Then 
    If Apple = "" And Banana = "" Then
        strSQL = strSQL & " AND (myApple = 0 AND myBanana = 0)"
    End If
End If

第一个结果:

myApple myBanana
 0       0
 0       0
 continue...

//第二

If int(Inventory) <> -1 Then    
    If Apple = "" And Banana = "" Then
        strSQL = strSQL & " AND (myApple <> 0 OR myBanana <> 0)"
    End If
End If

第二个结果:

 myApple myBanana
     0       5
     1       0
     continue...

我想看到的结果:

myApple myBanana
     0       0
     0       0
     0       5
     1       0
     6       0
     0       0
  continue.....
4

1 回答 1

2

尝试使用这个技巧

If Apple = "" And Banana = "" Then
    strSQL = strSQL & " AND (1 = " + If (Inventory) <> 0 Then "1" else "0" + " AND (myApple = 0 AND myBanana = 0))"       
    strSQL = strSQL & " AND (1 = " + If (Inventory) <> -1 Then "1" else "0" + " AND(myApple <> 0 OR myBanana <> 0))"
End If

所以为 Inventory = -1 获取 sqlwhere

AND (1 = 1 AND (myApple = 0 AND myBanana = 0)) AND (1 = 0 AND (myApple <> 0 OR myBanana <> 0))
于 2013-11-15T07:26:10.543 回答