top 5 *  atop 10 * atop 20 * b 这要怎么合并?

解决方案 »

  1.   

    select top 20 *,row_number() over (Order by id )  from  tableName
    选出前20条.然后 择机用前5条,或者是前10条
      

  2.   

    是sql2000
    不过还有就是里面包含不同的表(表1和表2)
      

  3.   

    貌似没有必要吧,不同的条件不同的表,
    要么就用动态传参方式
    declare @top int, @tbname sysname
    select @top = 5 ,@tbname =N'[表1]'
    print 'select top ' + str(@top) + ' from ' + @tbname + ' order by adddate asc 'select @top = 10 ,@tbname =N'[表1]'
    print 'select top ' + str(@top) + ' from ' + @tbname + ' order by adddate asc 'select @top = 20 ,@tbname =N'[表2]'
    print 'select top ' + str(@top) + ' from ' + @tbname + ' order by adddate asc '
    --exec ('select top ' + str(@top) + ' from ' + str(@tbname) + ' order by adddate asc ')
    /*
    select top          5 from [表1] order by adddate asc 
    select top         10 from [表1] order by adddate asc 
    select top         20 from [表2] order by adddate asc 
    */