做个存储过程,然后在存储过程用if else进行判断.例如:if 参数 = ''
   select ....
else
   select ....

解决方案 »

  1.   

    select * from T where col=isnull(参数,col)--参数为null
      

  2.   

    create table tb(a int,b int,c int)
    insert into tb select 1,1,1
    insert into tb select 2,2,2
    insert into tb select 3,3,3
    insert into tb select 4,4,4create proc proc_tb
    @a int=-1
    as
    begin
    if @a=-1
    select * from tb
    else 
    select * from tb where a=@a
    endexec proc_tb
    a b c
    1 1 1
    2 2 2
    3 3 3
    4 4 4
    exec proc_tb 1
    a b c
    1 1 1
      

  3.   

    select   *   from   T   where   col= isnull不好用
      

  4.   

    不用存储过程行不默认值给什么啊?
    select * from  T  where  col=  默认值?
      

  5.   

    string sql="select * from a";
    if(txtid.text !="")
    {
    sql += " where id='"+txtid.text+"'";
    }
    这意思?
      

  6.   

    我目前在用gridview 显示数据 用dropdownlist(下拉菜单)做查询条件我是想如果下拉菜单中什么都不选 让GRIDVIEW 直接显示所有数据
      

  7.   

     if (!Page.IsPostBack)
    {
    string   sql="select   *   from   a"; 
        查询+绑定gridview
    } protected void BtnSelect_Click(object sender, ImageClickEventArgs e)
    {
    string   sql="select   *   from   a"; 
    if(dropdownlist.SelectedItem.Text != "全部")
    sql+=" where 字段='"+dropdownlist.SelectedItem.Text+"'";
    }
      

  8.   

     select * from table
     where a=a   --a为列名 我想将列名作为默认值怎么办?
      

  9.   

    if   参数   =   '' 
          select   .... 
    else 
          select   ....