Hi all,
I have 100 rows in my database table , can you tell me a select query
which returns the rows between 51 and 100 ( it should be generic of my
choice of range)
Thanks in advance
AlertAdminAlertAdmin wrote:
> Hi all,
> I have 100 rows in my database table , can you tell me a select query
> which returns the rows between 51 and 100 ( it should be generic of my
> choice of range)
> Thanks in advance
> AlertAdmin
You haven't specified how you intend to determine the row number.
Assuming you have a key column on which to base the row number, try the
following in SQL Server 2005:
DECLARE @.from INTEGER, @.to INTEGER;
SET @.from = 51;
SET @.to = 100;
SELECT col1, col2
FROM
(SELECT ROW_NUMBER() OVER (ORDER BY key_col) row_num,
col1, col2
FROM your_table) AS T
WHERE row_num BETWEEN @.from AND @.to ;
For other solutions see:
http://www.aspfaq.com/show.asp?id=2120
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Thanks it works fine
No comments:
Post a Comment