TOP statement doesn't accept a variable
From: Derek Ruesch (anonymous_at_discussions.microsoft.com)
Date: 09/21/04
- Next message: Tod: "Re: Very Frustrating Problem with DateTime"
- Previous message: Alejandro Mesa: "Re: Numeric in VARCHAR field"
- Next in thread: Anith Sen: "Re: TOP statement doesn't accept a variable"
- Reply: Anith Sen: "Re: TOP statement doesn't accept a variable"
- Reply: alien2_51: "Re: TOP statement doesn't accept a variable"
- Reply: David Portas: "Re: TOP statement doesn't accept a variable"
- Reply: Aaron [SQL Server MVP]: "Re: TOP statement doesn't accept a variable"
- Reply: Joe Celko: "Re: TOP statement doesn't accept a variable"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 21 Sep 2004 13:06:25 -0700
The following stored procedure is designed to return the
given row number from a query.
CREATE PROCEDURE returnrownumber @rownumber INT AS
SELECT TOP 1 Name
FROM (SELECT TOP @rownumber Name
FROM tblEmployee
ORDER BY Name) DerivedTbl
ORDER BY Name DESC
However when I run this procedure the following error is
returned: "Incorrect syntax near the keyword '@rownumber'.
Incorrect syntax near the keyword 'ORDER'." It looks like
the use of a variable is not allowed in the TOP clause of
a select statement. If this is the case is there another
way to make this stored procedure work?
I greatly appreciate any help. Thanks.
Derek Ruesch
- Next message: Tod: "Re: Very Frustrating Problem with DateTime"
- Previous message: Alejandro Mesa: "Re: Numeric in VARCHAR field"
- Next in thread: Anith Sen: "Re: TOP statement doesn't accept a variable"
- Reply: Anith Sen: "Re: TOP statement doesn't accept a variable"
- Reply: alien2_51: "Re: TOP statement doesn't accept a variable"
- Reply: David Portas: "Re: TOP statement doesn't accept a variable"
- Reply: Aaron [SQL Server MVP]: "Re: TOP statement doesn't accept a variable"
- Reply: Joe Celko: "Re: TOP statement doesn't accept a variable"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|