April 8, 2002 at 4:00 am
How I can get the data of record number 50 to 80 from any table on Sql server database.
April 8, 2002 at 4:39 am
Try the follwoing format if you have a unique item key (not primary key, I mean column or comibnation of columns that are unique) and the table will be ordered by it.
For this example I have a States table for our service are that contains some, not all, states and I want the 2nd thru 5th states.
The table is defined in DDL as
CREATE TABLE [States] (
[StateIndex] [int] IDENTITY (1, 1) NOT NULL ,
[statename] [varchar] (50) NULL ,
[stateNumber] [varchar] (6) NULL ,
[Abbrev] [varchar] (2) NOT NULL ,
[Org] [char] (3) NOT NULL CONSTRAINT [DF_States_Org] DEFAULT ('000'),
CONSTRAINT [PK_States2] PRIMARY KEY CLUSTERED
(
[Abbrev]
) WITH FILLFACTOR = 90 ON [PRIMARY]
) ON [PRIMARY]
GO
The query I use the get the states is as follows.
SELECT * FROM states oSt WHERE
(SELECT count(abbrev) + 1 FROM States iSt WHERE iSt.Abbrev < oSt.Abbrev) BETWEEN 2 AND 5
ORDER BY Abbrev
"Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy