finding top n rows from a table-n should be passed as parameter : LUSENET : SQL Server Database Administration : One Thread

i want to get first n rows from a table.. my SP looks like this CREATE procedure temp @n integer AS select top @n from emp

-- Anonymous, January 01, 2004



Use SET ROWCOUNT rather than TOP in your stored procedure.

For instance, to select the top n rows of the authors table (in the pubs database) you could use a stored procedure like:

CREATE PROCEDURE top_authors @n integer AS SET ROWCOUNT @n SELECT * FROM authors ORDER BY au_id

Hope this helps,


-- Anonymous, January 05, 2004

Moderation questions? read the FAQ