to wanghu(不懂就是不懂) 如果你的10和11条记录相同,就会去11条记录Look: Select Top 10 with ties name from listtab order by name
用ADO来实现,Recordset.PageSize可以设置,每次从数据库提取得行数,自动处理.
使用SET ROWCOUNT,以下是BOL提供的示例 Examples SET ROWCOUNT stops processing after the specified number of rows. In this example, note that x rows meet the criteria of advances less than or equal to $5,000. However, from the number of rows returned by the update, you can see that not all rows were processed. ROWCOUNT affects all Transact-SQL statements.USE pubs GO SELECT count(*) AS Cnt FROM titles WHERE advance >= 5000 GOHere is the result set:Cnt ----------- 11 (1 row(s) affected)Now, set ROWCOUNT to 4 and update all rows with an advance of $5,000 or more.-- SET ROWCOUNT to 4. SET ROWCOUNT 4 GO UPDATE titles SET advance = 5000 WHERE advance >= 5000 GO
第N次N=5 declare @n int declare @sql nvarchar(500) set @n=5set @sql='select top 10 * from tablename where tablesid not in (select top '+str((@n-1)*10) from tablename )exec(@sql)
set @sql='select top 10 * from tablename where tablesid not in (select top '+str((@n-1)*10)+' from tablename )
Examples
SET ROWCOUNT stops processing after the specified number of rows. In this example, note that x rows meet the criteria of advances less than or equal to $5,000. However, from the number of rows returned by the update, you can see that not all rows were processed. ROWCOUNT affects all Transact-SQL statements.USE pubs
GO
SELECT count(*) AS Cnt
FROM titles
WHERE advance >= 5000
GOHere is the result set:Cnt
-----------
11 (1 row(s) affected)Now, set ROWCOUNT to 4 and update all rows with an advance of $5,000 or more.-- SET ROWCOUNT to 4.
SET ROWCOUNT 4
GO
UPDATE titles
SET advance = 5000
WHERE advance >= 5000
GO
declare @n int
declare @sql nvarchar(500)
set @n=5set @sql='select top 10 * from tablename where tablesid not in (select top '+str((@n-1)*10) from tablename )exec(@sql)