SQL code used by a select statement to output the N records of a table

Source: Internet
Author: User

Last week, I was asked by an online friend how to select the nth record of the nth table in SQL2000? (That is, how do I modify the statement 'select ID, name, title from website order by ID DESC 'to explain to the target)
I just gave it back.
Select ID, name, title from website where id = N
Finally, this old man said that if the ID is wrongly formed, it would be okay. If there is a record, the ID will not work anymore, so far, we can understand what he really means. So I thought about the weekly meeting time at the company. Give him the following answer ﹕

-- Select top 1 [ID], [name, title from website
-- Where not [ID] In (select top 11 [ID] From website order by [ID] ASC) order by [ID] ASC
Declare @ strsql varchar (200), @ inttopn int
Set @ inttopn = 11
Set @ strsql = 'select top 1 [ID], [name, title from website where not [ID] In (select top '+ Cast (@ inttopn as varchar (10 )) + '[ID] From website order by [ID] ASC) order by [ID] ASC'
Print @ strsql
Exec (@ strsql)

After that, I felt that there should be a better solution, but I couldn't think of it again! Put it here for discussion. If you have the best solution, please leave it blank!

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.