select top 2* from tableA如果tableA里只有一条纪录的话,这条语句,执行返回的是 1 条,而不是2条。我该怎么处理,如果返回的不是2条,就打印错误。总不能,select count(*) from (select top 2* from tableA) as tableB吧?谢谢!

解决方案 »

  1.   

    if(select count(*)from tb)>1 
    begin
      select top 2 * from tb
    end
    else
    begin
      select * from tb
      union all select * from tb
    end
      

  2.   

    vchao13() 的方法不太好吧。总之,我这个top的件数是个变量,比如说,如果变量是2的话,只检索出一条,就debug.print错误。有没有办法。?
      

  3.   

    select top 2 * from tableA
    if @@rowcount <> 2
    print 'error'
      

  4.   

    if(select count(*)from tb)>1 
    begin
      select top 2 * from tb
    end
    else
    begin
      select * from tb
      union all select * from tb
    end
      

  5.   

    if(select count(*)from tb)>1 
    begin
      select top 2 * from tb
    end
    else
    begin
      select * from tb
      union all select * from tb
    end