我正在运行一个简单的查询来获取某些表的前5000行:
SELECT TOP 5000
accountid, account, accountmanagerid, mainphone, alternatephone, fax, email, webaddress, createuser, modifyuser, createdate, modifydate, addressid, shippingid
FROM sysdba.account
WHERE 1 = 1
AND 1 = 1
ORDER BY accountid asc
这完全适用于sql server 2008,但不幸的是现在我发现自己试图运行这个以前工作的脚本来对抗SQL Server 2000.它似乎拒绝了top命令。
如何在此版本的sql server上取回我的5000行?
答案 0 :(得分:3)
在SQL Server 2000中没有TOP关键字。但是,您可以使用rowcount来过滤热门记录。您可以修改上述查询,如下所示:
-- 1=1 is NOT needed unless you are appending this string as dynamic SQL
SET ROWCOUNT 50
SELECT
accountid, account, accountmanagerid, mainphone, alternatephone, fax, email, webaddress, createuser, modifyuser, createdate, modifydate, addressid, shippingid
FROM sysdba.account
ORDER BY accountid asc
答案 1 :(得分:2)
没有TOP关键字,您也可以按照以下方式获得此问题的解决方案 -
select * from
(
select t_1.*,rownum c_1 from
(
select accountid,account,accountmanagerid,mainphone,alternatephone,
fax,email,webaddress,createuser, modifyuser,createdate,modifydate,addressid,hippingid
FROM sysdba.account
WHERE 1 = 1-- whatever condition
AND 1 = 1 -- condition 2
ORDER BY accountid asc
)t_1
)
where c_1 <5000
order by c_1