日期:2014-05-18  浏览次数:20357 次

关于select top 的问题,,,,求助!
select   top   2*   from   tableA

如果tableA里只有一条纪录的话,这条语句,执行返回的是   1   条,而不是2条。

我该怎么处理,如果返回的不是2条,就打印错误。

总不能,

select   count(*)   from   (select   top   2*   from   tableA)   as   tableB吧?

谢谢!

------解决方案--------------------
if(select count(*)from tb)> 1
begin
select top 2 * from tb
end
else
begin
select * from tb
union all select * from tb
end
------解决方案--------------------
select top 2 * from tableA
if @@rowcount <> 2
print 'error '