有一个查询数据库的操作,假设为
select a,b,c from table
但是有6-7个选项条件(可以全部不选,也可多选、全选),要求根据用户的选择来查询,难道只能用穷举法来写select语句吗,有没有什么好的方法
select a,b,c from table
但是有6-7个选项条件(可以全部不选,也可多选、全选),要求根据用户的选择来查询,难道只能用穷举法来写select语句吗,有没有什么好的方法
调试欢乐多
sql=sql & " and "
endifif 条件2 then
sql=sql & " and "
endif
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
http://feiyun0112.cnblogs.com/
Private Sub Command2_Click()
Dim strSql As String
Dim i As Integer
For i = 0 To 2
If Check1(i).Value = 1 Then
strSql = strSql & Check1(i).Caption & ","
End If
Next
strSql = Mid(strSql, 1, Len(strSql) - 1)
End Subsql="select " & strSql & " from TableName"