select top 10 mem_fname,mem_lname,sum(cpr_cp) from CprAndMem where cpr_date >= ? and cpr_date <= ?
group by mem_fname,mem_lname
order by sum(cpr_cp) desc
如果上面top 10 的10 要做为参数 是不是为语句改为如下:
select top ? mem_fname,mem_lname,sum(cpr_cp) from CprAndMem where cpr_date >= ? and cpr_date <= ?
group by mem_fname,mem_lname
order by sum(cpr_cp) desc
还有 第一个参数,也就是 top ?的?的类型是什么呢?

解决方案 »

  1.   

    top 后面只能带常数的。exec('select top ' + @n + ' mem_fname,mem_lname,sum(cpr_cp) from CprAndMem where cpr_date >= ? and cpr_date <= ?
    group by mem_fname,mem_lname
    order by sum(cpr_cp) desc ')
      

  2.   

    在数据环境的text中换sql语句
    "select top" & n & "mem_fname,mem_lname,sum(cpr_cp) from CprAndMem where cpr_date >= ? and cpr_date <= ?
    group by mem_fname,mem_lname
    order by sum(cpr_cp) desc"