select * from 表 where 货物名称=(CASE WHEN @hwmc<>'' THEN @hwmc ELSE 货物名称 END)

解决方案 »

  1.   

    select * 
    from 表 
    where @hwmc = '' or 货物名称 = @hwmc
      

  2.   

    select * from 表 where 货物名称 like case when @hwmc = '' then '%' else @hwmc end
      

  3.   

    if @hwmc<>'' 
    select * from 表 where 货物名称=@hwmc
      

  4.   

    不过,一般是先作判断:if @hwmc<>''
    select * from 表 where 货物名称=@hwmc
    else
    select * from 表
      

  5.   

    select * from 表 where 货物名称 like (CASE WHEN @hwmc<>'' THEN @hwmc ELSE '%' END)
      

  6.   

    看漏了,是
    select * from 表 where 货物名称 like case when @hwmc = '' then '%' else @hwmc end
    这样,或者用if语句
      

  7.   

    declare @sql varchar(8000)
    declare @hwmc varchar(200)
    select @sql='select * from 表 '
    if @hwmc ='' 
    begin
    select @sql='select * from 表 '
    end 
    if @hwmc<>'' then
    begin
    select @sql=@sql+' where 货物名称='''+@hwmc+''''
    end
    exec(@sql)
      

  8.   

    select * from 表 where 货物名称 = isnull(@hwmc,'')
      

  9.   

    没那么复杂吧,呵呵~~
    select * from 表 where 货物名称 = isnull(@hwmc,'')
      

  10.   

    错了,sorry!
    select * from 表 where (货物名称 = isnull(@hwmc,'') or isnull(@hwmc,'') = '')