首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

关于select top 的有关问题,

2012-02-15 
关于select top 的问题,,,,求助!selecttop2*fromtableA如果tableA里只有一条纪录的话,这条语句,执行返回的

关于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 '

热点排行