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!