Re: TOP statement doesn't accept a variable
From: alien2_51 (dan.billow"at"n.o.s.p.a.m.monacocoach.commercialversion)
Date: 09/21/04
- Next message: David Portas: "Re: TOP statement doesn't accept a variable"
- Previous message: Anith Sen: "Re: TOP statement doesn't accept a variable"
- In reply to: Derek Ruesch: "TOP statement doesn't accept a variable"
- Next in thread: David Portas: "Re: TOP statement doesn't accept a variable"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 21 Sep 2004 13:12:55 -0700
DECLARE @rowcount INT
SET @rowcount = 1
SET ROWCOUNT @rowcount
SELECT * FROM dbo.Table_Name
"Derek Ruesch" <anonymous@discussions.microsoft.com> wrote in message
news:0f0b01c4a016$79642f30$a601280a@phx.gbl...
> 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: David Portas: "Re: TOP statement doesn't accept a variable"
- Previous message: Anith Sen: "Re: TOP statement doesn't accept a variable"
- In reply to: Derek Ruesch: "TOP statement doesn't accept a variable"
- Next in thread: David Portas: "Re: TOP statement doesn't accept a variable"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|