自己写几个函数吧
不管是否存在,每个参数:
AddToSearch(数据库字段, 比较形式, 值)再调用BuildSearchSQL(strWhere)返回strWhere.....
//BuildSearchSQL(strWhere) 自己写啊   呵呵

解决方案 »

  1.   

    string sqlStr = "select * from table where ";
    if (i == 0)
      sqlStr += " and a = 10 and b < 50";
    if (i == 1)
      sqlStr += " and a > 4 and b < 100";sqlStr = sqlStr.Replace("where  and", "where");
      

  2.   

    string sql = "select * from table1 where 1=1 ";if (text1 != "") sql += " and a=" + int.parse(text1);
    if (text2 != "" ) sql += " and b < "+  + int.parse(text2);
    ..............
    当然使用StringBuilder效率更高。
      

  3.   

    你的查询条件是由谁定义呢? 
    偶是提供一个窗口给用户建立的, 有如下几个控件,可以简单地连接各个内容生成查询字串的条件部份ComboBox : 表名列表ComboBox : 关系运算符列表
    ComboBox : 字段列表
    ComboBox : 比较运算符列表
    TextBox等: 值
      

  4.   

    WhereStr = "where 1>0"
                If _Employee_Id <> "" Then
                    WhereStr = WhereStr & "F_ID='" & _User_TypeID & "'"
                End If
                If _UserTypeName <> "" Then
                    WhereStr = WhereStr & "F_Name='" & _UserTypeName & "'"
                End If
                MySqlStr = SqlStr & WhereStr & " order by F_Name"
      

  5.   

    CREATE PROCEDURE StoredProcedure1
    @a int,
    @b int,
    @c vachar(100)
    asif (@a <4)
    begin
    execute (执行的SQL语句)
    end
    else if (@a =10)
    begin
    execute (执行的SQL语句)
    end
    else if ...........
      

  6.   

    我觉得可以这样吧,如果你得查询条件是通过控件输入的,那你可以在控件的
    触发事件中写入对某个string的操作代码,一个条件一个条件的加上去,就可以了,
    只是最好判断一下是否语法正确就行。这个方法在事件中成功实现过
      

  7.   

    oh,是我的问题描述得不清楚,我是想在存储过程中根据参数是否空值来判断。
    在sql server区有人解决了,谢谢各位。