是啊,是一个动态的sql查询,如何写呢?欢迎来讨论

解决方案 »

  1.   

    先添加一个text名为txtsql,将你的查询信息显示在内,cbofield对应问题内容
    cbooperator对应包含,txtvalue对应abcIf form.cbooperator.Text = "包含" Then
                    form.txtsql.Text = .txtsql.Text + form.cbofield.Text + " like '*" + form.txtvalue.Text + "*'"
                Else
                   form .txtsql.Text = form.txtsql.Text + form.cbofield.Text + form.cbooperator.Text + "'" + form.txtvalue.Text + "'"
                End If
      

  2.   

    你之前的贴子已经给了你方法了,和你现在的这个是一个意思的Private Sub cmdB_Query_Click()
    Dim SQL As String
    Dim Qu As New Collection
    Dim opera As New CollectionIf Qu.Count = 0 Then
        Qu.Add "rylx"
        Qu.Add "rybh"
        Qu.Add "rymc"
        Qu.Add "xzmc"
        Qu.Add "zy" 
        ‘以上是你表中的要查询的列名
        opera.Add "='"
        opera.Add "<>'"
        opera.Add "> '"
        opera.Add ">='"
        opera.Add "<='"
        opera.Add "<='"
        opera.Add " like '%"
        opera.Add " not like '%"
    End IfSQL = "select rybh,rymc,password,rylx,xzmc,zy from ry where "
    SQL = SQL & Qu(cobQuery_dx(0).ListIndex + 1)
    SQL = SQL & opera(cobQuery_ys(0).ListIndex + 1)
    SQL = SQL & txtQuery(0).Text
    If cobQuery_ys(0).ListIndex = 6 Or cobQuery_ys(0).ListIndex = 7 Then SQL = SQL & "%"
    SQL = SQL & "'"If Check1.Value = 1 Then
      SQL = SQL & " and "
      SQL = SQL & Qu(cobQuery_dx(1).ListIndex + 1)
      SQL = SQL & opera(cobQuery_ys(1).ListIndex + 1)
      SQL = SQL & txtQuery(1).Text
      If cobQuery_ys(1).ListIndex = 6 Or cobQuery_ys(1).ListIndex = 7 Then SQL = SQL & "%"
      SQL = SQL & "'"
    End If
    此外,这个程序可以用又条件查询!就是那个check1.value来决定!
      

  3.   

    这个应该是一个动态sql,表是确定了,里面的条件没有确定,不过根据你列出的条件只有一条,所以sql很好写。combo1是需要判定的字段,combo2是选择相应的谓词。combo3是具体值。
    strsql="select * from tablename where " & combo1.list(combol1.listindex) & combo2.list(combo2.listindex) & combo3.list(combol3.listindex)combo2的写法就看你自己怎么写了,写的简单,操作也简单。
      

  4.   

    用SELECT CASE语句,对COMBO1,COMBO2的TEXT编程,从而修改sql语句
      

  5.   

    如果combo2写成不是中文,而是我们sql中的操作,比如= > <,岂不是连case都不用了  :P