SELECT TOP

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Elie Grouchko (egrouchko_at_hotmail.com)
Date: 01/23/05


Date: Sun, 23 Jan 2005 17:48:59 +0200

Hi All

I am writing a stored procedure to retrieve the top n rows of a SELECT
statement.

I tried passing the number of rows as a variable (topcount in the example),
but I get a syntax error:

Am I missing something?

Thanks in advance

Elie Grouchko

CREATE PROCEDURE Proc_SelectTopForumCommentsOrderByDate
@topcount int,
@twc_comment_subject int
AS
SELECT TOP @topcount * FROM [twt_comment] WHERE
([twc_comment_subject] = @twc_comment_subject)
AND ([twc_comment_id] != @twc_comment_subject)
AND ([twc_comment_state] = 2) ORDER BY [twc_comment_date] DESC