exec 'select a from table group by'+@b

解决方案 »

  1.   

    exec ('select A from table group by '+@B)
      

  2.   

    不好意思,写错了,应该是要
    默认,不输入参数的时候select A from table,全部选出来输入参数的时候select A from table where B=@B,只选出B=@B的
      

  3.   

    if isnull(@B, '')='' 
      exec('select A from table')
    else
      exec('select A from table where B='''+@B+'''')
      

  4.   

    select A from table where (@B is null) or ((B=@B) and (@B is not null))
      

  5.   

    if @B is null
      select A from table
    else
      exec ('select A from table group by '+@B)