MSSQL 有一表A 字段 id, temName, temId, tempContents 其中temName为模板名,现要求根据要求能不能取得数据按temName排序,取得con_no1 5000条后再取 con_no2 5000条 以次取下去。。只到完为止,不足5000就取模板实际数。    
  con_no1 120000条
  con_no2 110000条
  con_no3 5000条
  con_no4 70000条
  con_no5 5000条
  con_no6 20000条
  con_no7 100000条
  con_no8 200000条
  con_no9 100000条
  con_no10 2000条
  con_no11 2000条
  con_no12 6000条   
  共10万数据
    

解决方案 »

  1.   

    select top 5000 * from A where temName ='con_no1' union all
    select top 5000 * from A where temName ='con_no2' union all
    select top 5000 * from A where temName ='con_no3' union all
    .....
    select top 5000 * from A where temName ='con_no11' union all
    select top 5000 * from A where temName ='con_no12' 
      

  2.   

    con_no1 是不是temName 啊,不是的话上面的没有排序的了,要换的
      

  3.   

    select * from(select row_number() over (order by temname) as rowno,* from a) tmp where rowno > 0 and rowno<500取第几个500 就把0和500乘几。
      

  4.   

    数据库是sql2000的没有row_number()
    楼主三的方法。。太复杂了。。数量大的话。写SQL会写死的。而且模板也比较多35个。目前。。这样要写多少次?