-3

2 つの If ステートメントの条件結果をマージしたいと考えています。最初のifステートメントの結果は両方とも0の結果のみを示し、2番目のifステートメントの結果は0よりも大きくなければなりません...私がしたいのは、2番目の条件をそのままにして、ifステートメントが私のコードのように最初に変更することです...

私のコード

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...

//2番

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

2番目の結果:

 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 に答える