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

解决方案 »

  1.   

    select * from table where exists select aa,bb,cc from table1
      

  2.   

    查询条件是从listbox中获得的。个数不确定
      

  3.   

    自己拼接字符串:dim sql as string 
    dim a
    a=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
      

  4.   

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

  5.   

    加个判断
    if str1 = “” then
    str = List1.List(i)
    else
       king06的代码
    end if
      

  6.   

    in子句至少分二种数据类型要处理,根据list1.count声明一个动态数组,用for循环list1添加其内容到数组中,用3楼的代码就行了...
      

  7.   

    在C#里面怎么写参数化sql语句,参数个数不定,就像多条件查询 
      

  8.   

    这几天忙没来,
    你看到我代码里面写了一句 str1 = Mid(str1, 2) 吗?
    不管是不是只有一个选项,都把最前的一个逗号去掉了