天天看點

SQL Server 2000查詢n到m條記錄

 SQL Server 2000查詢n到m條記錄?

(1)select top m * from tablename where id not in (select top n id from tablename)

(2).

           select top m * into 臨時表(或表變量) from tablename order by columnname -- 将top m筆插入

           set rowcount n

           select * from 表變量 order by columnname desc

(3).

        select top n * from

       (select top m * from tablename order by columnname) order by columnname desc

(4)如果tablename裡沒有其他identity列,那麼:

        select identity(int) id0,* into #temp from tablename

        取n到m條的語句為:

          select * from #temp where id0 >=n and id0 <= m

        如果你在執行select identity(int) id0,* into #temp from tablename這條語句的時候報錯,那是因為你    的 DB中間的select into/bulkcopy屬性沒有打開要先執行:

exec sp_dboption 你的DB名字,'select into/bulkcopy',true

(5).如果表裡有identity屬性,那麼簡單:

          select * from tablename where identity col between n and m

本文轉自yonghu86 51CTO部落格,原文連結:http://blog.51cto.com/yonghu/1321442,如需轉載請自行聯系原作者