SELECT * FROM table where ( @name1 = ' ' or name1 = @name1 ) and ( @name=2 = ' ' or name2 = @name2)
我这里 name1是数据库字段名 @name1是界面传来的参数
我想要的效果是 多个文本框 用户可以任意输几个 都可以查询。。没输入的不参与搜索
 这个语句要怎么样修改啊 

解决方案 »

  1.   


    --使用null值就可以了
    SELECT * FROM table where ( name1 = ' ' or name1 = @name1 or name1 =null) 
    and (name2 = ' ' or name2 = @name2 or name2 =null) 
      

  2.   

    SELECT * FROM table where [email protected]() and [email protected]()....... 
      

  3.   

    用union 看看可以不可以?
      

  4.   

    动态sql语句就可以了阿! T_SQL="select * from table where 1=1 "
     
     if 条件=True
        T_SQL=T_SQL + " and 条件"
     .....