Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

top 5 like statment 1

Status
Not open for further replies.

kyriakos70

Programmer
Jul 24, 2008
87
GR
Hello,
I want a statment to work like top 5 but not only for the first records but for a page of records eg from record 5 to 10, I have used this but gave me an error :

'SELECT TOP 5 * FROM scan WHERE id NOT IN (SELECT TOP 4 * id FROM scan Where id like :)aaaid))'

also would like to have a parameter to view particular records in the range.

Thank you
Kyriakos
 
yeah, your best bet for doing this would be to use the row_number function and then use where to limit the results into pages...

--------------------
Procrastinate Now!
 
I found this is it correct? I mean there must be something else like between etc., can you give me an example about my query, more simple?
USE AdventureWorks2008R2;
Code:
GO
WITH OrderedOrders AS
(
    SELECT SalesOrderID, OrderDate,
    ROW_NUMBER() OVER (ORDER BY OrderDate) AS 'RowNumber'
    FROM Sales.SalesOrderHeader 
) 
SELECT * 
FROM OrderedOrders 
WHERE RowNumber BETWEEN 50 AND 60;

thank you
Kyriakos
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top