views:

56

answers:

2

(row number not stored in db)

------------------------
|      |     A   |     | (1)
------------------------
|      |     B   |     | (2)
------------------------
|      |     C   |     | (3)
------------------------ -----Page 1
|      |     D   |     | (4)
------------------------
|      |     E   |     | (5)
------------------------
|      |     F   |     | (6)
------------------------ -----Page 2
|      |     F   |     | (7)
------------------------
|      |     F   |     | (8)
------------------------
|      |     G   |     | (9) -----Page 3

i.e. a search for "F" would return 6.

Thank You.

trying to do the firstr part of this: http://stackoverflow.com/questions/3579586/how-do-i-query-a-sql-database-to-return-the-first-page-containing-the-specified

Found these:
sequential row numbers from query

sqlite Retrieve Rownumber in sqlite

+1  A: 
SELECT COUNT(*)
FROM tbl
WHERE letter < 'F'

(you'll get the number minus one, so you would have to increment it by one afterwards)

Jasper
@Jasper: will this work for all data types?
Tommy
It does. But be aware that `NULL` values won't be included in the count.
dan04
A: 

try this, but I don't consider the performance

--create table
create table t(letter char(1))
go

--insert values
BEGIN TRAN
INSERT INTO t VALUES ('A')
INSERT INTO t VALUES ('B')
INSERT INTO t VALUES ('C')
INSERT INTO t VALUES ('D')
INSERT INTO t VALUES ('E')
INSERT INTO t VALUES ('F')
INSERT INTO t VALUES ('F')
INSERT INTO t VALUES ('F')
INSERT INTO t VALUES ('G')
COMMIT TRAN
GO

--and then try the select what you want
DECLARE @temp table(num int identity(1,1), letter char(1))

--use a temp table variable to store the data with row number
insert into @temp
SELECT * FROM t

--select the value
SELECT * FROM @temp WHERE letter = 'F'
GO

--drop the table finally
drop table t
GO
Tim Li