读书人

sql怎样解决多条件查询,该怎么解决

发布时间: 2012-01-29 21:39:32 作者: rapoo

sql怎样解决多条件查询
比如针对某个字段的多条件查询,现在知道的是可以用select * from table where 字段 in()
但现在in()里面的字段是不确定的,可以是2个也可以是5个等,怎么写呢?

[解决办法]
自己拼接字符串:

VB code
dim sql as string dim aa=array(2,3,410,99)'如果IN子句是数字a=join(a,",")    sql="select * from tb where id in ("& a &")"debug.? sql'如果IN子句是字符类型a=join(a,"','")    sql="select * from tb where id in ('"& a &"')"debug.? sql
[解决办法]
VB code
    Dim str1 As String    If List1.ListCount > 0 Then        For i = 0 To List1.ListCount - 1            str1 = str1 & "," & List1.List(i)        Next        str1 = Mid(str1, 2)    End If    strSQL="select * from table1 where 字段1 in (" & str1 & ")" 

读书人网 >VB

热点推荐