首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

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

2012-01-29 
sql怎样解决多条件查询比如针对某个字段的多条件查询,现在知道的是可以用select * from table where 字段

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 & ")" 

热点排行