我需要一個想法將以下「If's」條件轉換爲原始SQL語句。 (無動態SQL)將動態JOINS轉換爲SQL語句
Dim strVar1 as String, strVar2 as String, strVar3 as String, intSet Int32
.Append("SELECT * FROM TABLE_A as A ")
.Append("INNER JOIN TABLE_B as B ON A.Code=B.Code_A ")
If strVar1.Length > 0 Then
.Append("LEFT JOIN TABLE_C as C ON C.Code=A.Code_C ")
.Append("LEFT OUTER JOIN TABLE_D as D on C.Code=D.Code_C AND D.Col1 IN (1,NULL) ")
End If
If strVar2.Length > 0 Or strVar3.Length > 0 Then
.Append("LEFT OUTER JOIN TABLE_E as E ON A.Code=E.Code_A ")
.Append("LEFT OUTER JOIN TABLE_F as F ON E.Col1=F.Col1 ")
.Append("INNER JOIN TABLE_G ON as G ON F.Code=G.Code_F AND G.Col1=1 ")
End If
Select Case intType
Case 1 , 2
If intSet <> -1 Then
.Append("LEFT OUTER JOIN TABLE_H H on A.code=H.code_A AND H.code_H=1 AND H.Pos=1 ")
Else
.Append("LEFT OUTER JOIN TABLE_H H on A.code=H.code_A AND H.Pos=1 ")
End If
Case 3 , 4
End Select
intSet從哪裏來? 。附錄中的「With」在哪裏? – gbn 2011-06-10 07:38:39
只是一句話。 'D.Col1 IN(1,NULL)'應該是'(D.Col1 = 1或者D.Col1 IS NULL)' – 2011-06-10 07:41:18