Paging in sql server

This may not be the most elegant paging code for sql server but it solves the problem:

create database foobar
go

use foobar
go

drop table test
go
create table test(id int not null, name varchar(10) not null, primary key(id))
go

insert into test values (1,’one’)
insert into test values (2,’two’)
insert into test values (3,’three’)
insert into test values (4,’four’)
insert into test values (5,’five’)
go

select top 2 *
from test  
where id not in (select top 2 id from test)
order by id
go

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s