注意一下SQL优化方面的就行,把能把查询范围缩小到最小的条件放在where的最后,按照这个逐渐把6个条件排序一下就行。

解决方案 »

  1.   

    if (strclass1value != "-1")
            {
                sqlwhere += " and a.infoclassid=" + strclass1value;
            }
            if (strclass2value != "-1")
            {
                sqlwhere += " and a.infotypeid=" + strclass2value;
            }
            if (sendCorp != "-1")
            {
                sqlwhere += " and a.departid ='" + sendCorp + "'";        }
            if (strtitle != "")
            {
                sqlwhere += " and(";
                string[] titles = Regex.Split(strtitle, @"\s+", RegexOptions.Compiled);
                for (int i = 0; i < titles.Length; i++)
                {
                    if (i != 0) sqlwhere += " or ";
                    sqlwhere += "a.title like '%" + titles[i] + "%'";
                }
                sqlwhere += ")";
                //sqlwhere += " and a.title like '%" + strtitle + "%'";
            }
      

  2.   

    这样的拼装sql语句把,是最简单的
      

  3.   

    首先 sql = "where 1= 1 "
    然后
    if(条件1 !="")
    {
     sql += " and ..."
    }if(条件2 !="")
    {
            .............
     }
      

  4.   

    LZ的意思是选择的条件不固定 , 拼SQL语句怎么拼
      

  5.   


    string strs = "select * from biao " 
    int t=0;//记录条件数
    if(DropDownList1.SelectedValue!=null)
    {
    if t=0
       strs+=" where “;
    else
        strs+=" and“;
    strs+=" city='" +this.DropDownList1.SelectedValue + "'";
    } 其他选项依此类推·
      

  6.   

    就是拼接SQL语句啊,不为空就算一个条件,为空就不管,这样一循环就行了
      

  7.   

    string strs = "select * from biao " 
    int t=0;//记录条件数
    if(DropDownList1.SelectedValue!=null)
    {
    if t=0
       strs+=" where “;
    else
        strs+=" and“;
    strs+=" city='" +this.DropDownList1.SelectedValue + "'";
    t++;//
    } 其他选项依此类推·
      

  8.   

    怎么弄,就是随意搜索,有6个选择的条件,如果选择几个就搜索几个 
    如:
    选择第1个
    select * from table where city=条件
    选择第2个
    select * from table where jyfs =条件
    选择第1个和选择第2个
    select * from table where city=条件1 and jyfs =条件2....
    如此搜索
    希望老兄帮忙
      

  9.   

    写在存储过程 !条件用   条件1 or 条件2 or 条件3 ...............
      

  10.   

    写在存储过程 !条件用  条件1 or 条件2 or 条件3 ............... 行吗,or 不是或者吗,怎么不用and 啊spkl1()水泡 的 记录条件数 这个不错,我试试,不会在请教老兄
      

  11.   

    这样写,
    首先条件假如是满足的如
    String strSQL="select * from member where 1=1 ";
    '//下面开始判断
    if(!name.equals("")) strSQL+=" and name like '%"+name+"%'";
    if(!gender.equals("")) strSQL+=" and gender='""+gender+"'";