Query n to M records in SQL Server 2000

Source: Internet
Author: User
SQL Server 2000 queries n to M records?

 

(1) Select top M * From tablename where id not in (select Top n id from tablename) (2 ). Select top M * Temporary table (or table variable) from tablename order by columnname -- insert top M pen Set rowcount n Select * from Table variable order by columnname DESC (3 ). Select Top N * from (Select top M * From tablename order by columnname) Order by columnname DESC (4) If there are no other identity columns in tablename, then: Select Identity (INT) id0, * into # temp from tablename N to M statements: Select * from # temp where id0> = N and id0 <= m If you report an error when executing the Select Identity (INT) id0, * into # temp from tablename statement, this is because the select into/bulkcopy attribute in the middle of your DB is not enabled and must be executed first: Exec sp_dboption Your DB name, 'select into/bulkcopy', true (5). If the table contains the identity attribute, it is simple: Select * From tablename where identity Col between N and m
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.