Hello there,
I am writing a stored procedure that is a simple select query. I want the calling code to supply a maximum number of rows to be returned but I cannot get the code to work using this parameter. Here is my code:
When i check syntax, I get error 170, incorrect syntax on the line that contains 'SELECT TOP @maxItems'. If I replace @maxItems with a literal value the code checks out fine.
Could anyone show me my mistake?
Thanks in advance
DT
I am writing a stored procedure that is a simple select query. I want the calling code to supply a maximum number of rows to be returned but I cannot get the code to work using this parameter. Here is my code:
Code:
CREATE PROCEDURE dbo.selFeaturedItems
@maxItems int
AS
SELECT TOP @maxItems
pro_ID,
pro_Title,
pro_Text
FROM product
...
...
RETURN
When i check syntax, I get error 170, incorrect syntax on the line that contains 'SELECT TOP @maxItems'. If I replace @maxItems with a literal value the code checks out fine.
Could anyone show me my mistake?
Thanks in advance
DT