请问:我建立了一个数据库“ffyy”,字段有“姓名、性别、编号、职位”四个,当输入任意一个或多个字段时的数据库查询如何实现?

解决方案 »

  1.   

    dim sql as stringsql="select * from ffyy "
    if 姓名值<>"" then sql=" 姓名 like '%姓名值%'"
    if 性别值<>"" then sql & sql=" and 性别 like '%性别值%'"
    if 编号值<>"" then sql & sql=" and 编号 like '%编号值%'"
    if 职位值<>"" then sql & sql=" and 职位 like '%职位值%'"
    if left(sql,4)=" and" then
       sql=right(sql,len(sql)-4)
    end if
    if sql<>"" then
       rs.open "select * from ffyy where" & sql
    else
       rs.open "select * from ffyy"
    endif
      

  2.   

    上个错了,应该是
    dim sql as stringif 姓名值<>"" then sql=" 姓名 like '%姓名值%'"
    if 性别值<>"" then sql & sql=" and 性别 like '%性别值%'"
    if 编号值<>"" then sql & sql=" and 编号 like '%编号值%'"
    if 职位值<>"" then sql & sql=" and 职位 like '%职位值%'"
    if left(sql,4)=" and" then
       sql=right(sql,len(sql)-4)
    end if
    if sql<>"" then
       rs.open "select * from ffyy where" & sql
    else
       rs.open "select * from ffyy"
    endif
      

  3.   

    dim sql as string 
    sql="select * from ffyy "
    dim condition as string
    condition=""
    if txtName.text<>"" then condition= "姓名='" & txtName.text & "' "
    if txtSex.text<>"" then
       if condition="" then 
           condition="性别='" & txtSex.text & "' "
       else
           condition=condition & " and  性别='" & txtSex.text & "' "
    end if
    ..同上将编号和职位写完..
    if condition<>"" then sql=sql & " where " & condition   
    执行查询
      

  4.   

    3家楼上的都可以运行~
    xsp(半个程序员) 的比较全面!
      

  5.   

    to: liyijx(不懂Boy)你运行第一家的试试,看看对吗
    xsp(半个程序员) 的全面在哪里?
      

  6.   

    bruce_figo(管理员)的语句怎么总显示“缺少表达式”呢???
      

  7.   

    dim strsql  as string
    dim tmp_name as string
    dim tmp_sex as string
    dim tmp_code as string
    dim tmp_job  as string
    if 姓名值<>"" then 
       tmp_name=" and 姓名 like '%姓名值%'"
    else
       tmp_name=""
    endif
    if 性别值<>"" then 
       tmp_sex=" and 性别 like '%性别值%'"
    else
       tmp_sex=""
    endif
    if 编号值<>"" then 
        tmp_code=" and 编号 like '%编号值%'"
    else
        tmp_code=""
    endifif 职位值<>"" then 
       tmp_job=" and 职位 like '%职位值%'"
    else
       tmp_job=""
    endif
    '组合查询
    strsql=" select * from ffyy where 1=1 " & tmp_name & tmp_sex & tmp_code & tmp_jobif rs.state=adstateopen then rs.close
    rs.open strsql,conn,3,3